Get Current Location
-
Monday, May 21, 2012 3:21 PM
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
All Replies
-
Monday, May 21, 2012 5:05 PM
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:22 PM
It works fine now. I changed the Location Services to 'ON' for Safari in my iPad
Bala
-
Wednesday, May 23, 2012 8:15 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- Marked As Answer by Richard_BrundrittMicrosoft Employee, Owner Thursday, May 24, 2012 7:38 AM

