User Location

Bing
 

Obtaining a user’s location can easily be done using the W3C Geolocation API. This API is exposed through the navigator.geolocation property in the browser. The browser will display a notification to the user the first time this API tries to get the users location, and ask permission to share this data. The geolocation class has the following static methods.

NameReturn TypeDescription
getCurrentPosition(
successCallback:function,
errorCallback?:function,
opt?:PositionOptions)
Attempts to obtain the users location. If successful it will trigger the callback function. This callback will receive a Position object that contains coordinates of the user and possibly additional information such as accuracy speed, heading, altitude.
watchPosition(
successCallback:function,
errorCallback?:function,
opt?:PositionOptions)
numberMonitors the users position and triggers the callback if the user location information changes. This method will return a number which is the ID of this task. It can be used to clear/stop this task.
clearWatch(watchId:number)Clears/stops a watch position task with the specified ID.
NameTypeDescription
enableHighAccuracybooleanThis tells the browser that it would like to receive the best possible results. This may result in slower response times or increased power consumption. Default is false.
timeoutnumberThe maximum length of time (expressed in milliseconds) that is allowed to pass from the call until the corresponding successCallback is invoked. Default is Infinity.
maximumAgenumberIndicates that the application is willing to accept a cached position whose age is no greater than the specified time in milliseconds. Default is 0.
NameTypeDescription
coordsCoordinateContains the geographic coordinate information.
timestampThe time when the position object was acquired.
NameTypeDescription
latitudenumberThe latitude coordinate value.
longitudenumberThe longitude coordinate value.
altitudenumberThe altitude in meters above the WGS84 ellipsoid. This value is not always returned.
accuracynumberAccuracy level of the latitude and longitude coordinates in meters.
altitudeAccuracynumberAccuracy of the altitude value in meters. This value is not always returned.
headingnumberThe direction in which the device is pointed in degrees counting clockwise where true north is 0 degrees. This value is not always returned.
speednumberThe speed at which the device is travelling in meters per seconds. This value is not always returned.
Show: