Problem setting pushpin

Hello, Below is a very simple example of what I am trying to do. In the fucntion "GetMap" I do a Find on an address. That find should execute the function "GetLonLat". "GetLonLat" then sets the longitude/latitude to the var LonLat. Then in Function "GetMap", it should use that var to create the pushpin. You will notice I have a couple of alerts in the script. What is happening is the second alert (in function GetMap) fires first. Then the one in "GetLonLat" fires. The problem is that if I do not have the alerts in then the var LonLat is null at the time I use it for the VEPushPin.

Any Ideas? How do I make sure that the map.Find and GetLonLat gets execute prior to VEPushpin?

var map = null;
var LonLat=null;
function GetLonLat(results)
{
LonLat = results[0].LatLong
alert("First results: "+LonLat);
}
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
map.Find(null,"98503", 1, GetLonLat);
alert("Second result: "+LonLat);
var pin = new VEPushpin(1, LonLat, null, 'A point', 'location number ');
map.AddPushpin(pin);
}

[1232 byte] By [RNes] at [2007-12-31]
# 1
Shooting from the hip (as in totally untested) I'd try moving the pin creation to the callback.
Something like:
var map = null;
function GetLonLat( results )
{
if( results.Length > 0 )
{
map.AddPushpin( new VEPushpin(1,
results[0].LatLongLatLong, null ,'some', 'text' );
}
}
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
map.Find( null, '98503', 1, GetLonLag );
}
Harvester at 2007-10-10 > top of Msdn Tech,Windows Live Developer Forums,Virtual Earth: Map Control Development...
# 2

Harvester is spot on, the find call is asyc so while it is waiting for the result to return from the live.com server the rest of the js is executed.

Anything you want to do with the find result should be in the callback.

John.

SoulSolutions at 2007-10-10 > top of Msdn Tech,Windows Live Developer Forums,Virtual Earth: Map Control Development...

Windows Live Developer Forums

Site Classified