Partager via


User Location for V8 Web Control

Note

Bing Maps Web Control SDK retirement

Bing Maps Web Control SDK is deprecated and will be retired. Free (Basic) account customers can continue to use Bing Maps Web Control SDK until June 30th, 2025. Enterprise account customers can continue to use Bing Maps Web Control SDK until June 30th, 2028. To avoid service disruptions, all implementations using Bing Maps Web Control SDK will need to be updated to use Azure Maps Web SDK by the retirement date that applies to your Bing Maps for Enterprise account type. For detailed migration guidance, see Migrate from Bing Maps Web Control SDK and Migrate Bing Maps Enterprise applications to Azure Maps with GitHub Copilot.

Azure Maps is Microsoft's next-generation maps and geospatial services for developers. Azure Maps has many of the same features as Bing Maps for Enterprise, and more. To get started with Azure Maps, create a free Azure subscription and an Azure Maps account. For more information about azure Maps, see Azure Maps Documentation. For migration guidance, see Bing Maps Migration Overview.

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.

Name Return Type Description
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)
number Monitors 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.

PositionOptions Object

Name Type Description
enableHighAccuracy boolean This 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.
timeout number The maximum length of time (expressed in milliseconds) that is allowed to pass from the call until the corresponding successCallback is invoked. Default is Infinity.
maximumAge number Indicates that the application is willing to accept a cached position whose age is no greater than the specified time in milliseconds. Default is 0.

Position Object

Name Type Description
coords Coordinate Contains the geographic coordinate information.
timestamp The time when the position object was acquired.

Coordinate Object

Name Type Description
latitude number The latitude coordinate value.
longitude number The longitude coordinate value.
altitude number The altitude in meters above the WGS84 ellipsoid. This value is not always returned.
accuracy number Accuracy level of the latitude and longitude coordinates in meters.
altitudeAccuracy number Accuracy of the altitude value in meters. This value is not always returned.
heading number The direction in which the device is pointed in degrees counting clockwise where true north is 0 degrees. This value is not always returned.
speed number The speed at which the device is travelling in meters per seconds. This value is not always returned.

Examples

See Also