GeoLocationProvider Class
Contains methods for obtaining and displaying the user’s current location.
Note: |
|---|
| This functionality is only available on browsers that support the W3C GeoLocation API. |
Constructor
| Name | Definition | Description |
|---|---|---|
|
GeoLocationProvider |
|
Initializes a new instance of the GeoLocationProvider class. |
Methods
| Name | Definition | Return Value | Description |
|---|---|---|---|
|
addAccuracyCircle |
|
None |
Renders a geo location accuracy circle on the map. The accuracy circle is created with the center at the specified location, using the given radiusInMeters, and with the specified number of segments for the accuracy circle polygon. Additional options are also available to adjust the style of the polygon. |
|
cancelCurrentRequest |
|
None |
Cancels the processing of the current getCurrentPosition request. This method prevents the response from being processed. |
|
getCurrentPosition |
|
None |
Obtains the user’s current location and displays it on the map. Important:
The accuracy of the user location obtained using this method varies widely depending on the desktop browser or mobile device of the requesting client. Desktop users may experience low user location accuracy (accuracy circles with large radiuses), while mobile user location accuracy may be much greater (a few meters).
|
|
removeAccuracyCircle |
|
None |
Removes the current geo location accuracy circle. |
Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
{
// Set the map options
var mapOptions = {credentials:"Bing Maps Key"};
// Initialize the map
var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions);
// Initialize the location provider
var geoLocationProvider = new Microsoft.Maps.GeoLocationProvider(map);
// Get the user's current location
geoLocationProvider.getCurrentPosition();
}
</script>
</head>
<body onload="GetMap();">
<div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>
</body>
</html>
Note: