次の方法で共有


Specifying the Time-out Duration

To limit the time allowed for the Geolocation API to determine the location, developers can use the optional options parameter that is passed to getCurrentPosition or watchPosition. The timeout attribute denotes the maximum length of time (expressed in milliseconds) that is allowed to pass from the call to getCurrentPosition or watchPosition until the corresponding success callback is invoked.

The following line of code shows a call to getCurrentPosition that specifies the timeout attribute to be 60000 in the options parameter, in order to specify a time-out of one minute.

    navigator.geolocation.getCurrentPosition(successCallback,
                                             errorCallback,
                                             {timeout:60000});

If Windows Internet Explorer is unable to successfully acquire a new Position object before the given time-out elapses, and no other errors have occurred in this interval, the corresponding error callback will be invoked with a PositionError object whose code attribute is set to TIMEOUT. Be aware that the time that is spent obtaining the user permission is not included in the period covered by the timeout attribute. The timeout attribute applies only to the location acquisition operation.

The default value used for the timeout attribute is Infinity, if the options parameter to getCurrentPosition or watchPosition is omitted. If a negative value is supplied, the time-out value is considered to be zero.

In case of a getCurrentPosition call that times out, the error callback would be invoked only one time. In case of watchPosition, the error callback could be invoked repeatedly: the first timeout is relative to the moment watchPosition was called or the moment the user's permission was obtained, if that was necessary. Subsequent timeouts are relative to the moment when the implementation determines that the position of the hosting device has changed and a new Position object must be acquired.

Note  Support for the options specified in the options parameter depends on the location provider used by the computer or device running Windows Internet Explorer 9. There is no guarantee that options specified will affect the results returned by the location provider. For instance, if the location provider already has data ready to return, setting timeout to zero might not actually cause an error.

 

Getting the Current Location

Handling Errors

How to Create a Location-Aware Webpage

Watching for Location Changes