none
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:

    false});

    functiondisplayCenter(args) {

           

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

    varloc = args.center;

            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?


    Bala

    Monday, May 21, 2012 3:21 PM

Answers

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

                            navigator.geolocation.getCurrentPosition(
                                  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 () {
                                      alert("Error');
                                  }
                                );
                        }


    Bala

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


    Bala

    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 http://msdn.microsoft.com/en-us/library/hh125839.aspx


    MSFT
    Hemant Goyal

    Wednesday, May 23, 2012 8:15 PM