0 out of 2 rated this helpful - Rate this topic

GeoLocationProvider Class

Bing Services

Contains methods for obtaining and displaying the user’s current location.

Hh125833.note(en-us,MSDN.10).gifNote:
This functionality is only available on browsers that support the W3C GeoLocation API.

Constructor

Name Definition Description

GeoLocationProvider

GeoLocationProvider(map: Map )

Initializes a new instance of the GeoLocationProvider class.

Methods

Name Definition Return Value Description

addAccuracyCircle

addAccuracyCircle(center: Location , radiusInMeters:number, segments:number, options: PositionCircleOptions )

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

cancelCurrentRequest()

None

Cancels the processing of the current getCurrentPosition request. This method prevents the response from being processed.

getCurrentPosition

getCurrentPosition(options: PositionOptions )

None

Obtains the user’s current location and displays it on the map.

Hh125833.Important(en-us,MSDN.10).gifImportant:
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

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>

See Also

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.