Get Current Location RRS feed

  • Question

  • Hi,

    I am trying to show the current location on the map. I tried following code:

    // Initialize the location provider

    vargeoLocationProvider = newMicrosoft.Maps.GeoLocationProvider(map);

    // Get the user's current location

    geoLocationProvider.getCurrentPosition({ successCallback: displayCenter, showAccuracyCircle:


    functiondisplayCenter(args) {


    // Display the user location when the geo location request returns   

    varloc =;

            map.setView({ zoom: 12, center:

    newMicrosoft.Maps.Location(loc.latitude, loc.longitude) });


    But it works when I run the web application in IE. But if I try to access the application in iPhone/iPad Safari it is not moving to the current location.

    Is this the currect approach or is there any other way to get current location?


    Monday, May 21, 2012 3:21 PM


All replies

  • Also, I tried following way. The second alert is not working in Safari. Any idea?

    if (navigator.geolocation) {                        

                            alert(navigator.geolocation.getCurrentPosition);   // works in IE & Safari

                                  function (pos) {
                                      alert(navigator.geolocation.getCurrentPosition);  / not works in Safari
                                      var lat = pos.coords.latitude;
                                      var long = pos.coords.longitude;

                                      map.setView({ zoom: 12, center: new Microsoft.Maps.Location(lat, long) });

                                  function () {


    Monday, May 21, 2012 5:05 PM
  • It works fine now. I changed the Location Services to 'ON' for Safari in my iPad 


    Monday, May 21, 2012 5:22 PM
  • Also you can add errorback in getCurrentPosition method as below: 

    geoLocationProvider.getCurrentPosition({ errorCallback: function(object) { alert('Error callback invoked, error code '  + object.errorCode); } });

    The error code returned is documented here

    Hemant Goyal

    Wednesday, May 23, 2012 8:15 PM