Bing Maps Ajax API v7 Geolocation call back
-
Sunday, April 22, 2012 3:04 PM
I user Bing Maps Ajax v7 API to get user's location from the example [here][1]
Is it possible to wait until the callback is executed and until I get a longitude, latitude for the user's position or an error if he/she does not allow to get the position?
function test() {
//Call GetMap() to get position
GetMap();
//Wait until callback is finished
//Do something with user's location (result of the callback)
}
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({successCallback:displayCenter});
//Execute some more code with user's location
}
function displayCenter(args) {
// Display the user location when the geo location request returns
alert("The user's location is " + args.center);
}
[1]: http://207.46.16.251/en-us/library/hh125839.aspx
- Edited by salamis1948 Sunday, April 22, 2012 3:05 PM
- Edited by salamis1948 Sunday, April 22, 2012 3:06 PM
All Replies
-
Sunday, April 22, 2012 7:49 PMOwner
Yes, the key is to create another function with the code you want to run after the position GeoLocationProvider calls one of the callbacks and then call that method in the callback.http://rbrundritt.wordpress.com
- Marked As Answer by Richard_BrundrittMicrosoft Employee, Owner Monday, April 23, 2012 7:53 AM

