|
<html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script> <script> var map = null; var count = 0; var locations = ["Toronto, Ontario","New York, New York","Seattle, WA"]; function GetMap() { map = new VEMap(‘myMap’); map.LoadMap(); }
function FindLocation(searchstr) { if (searchstr != ”) { map.Find(null, searchstr, null, null, null, null, false, null, null, false, AddPin); } } function AddPin(layer, resultsArray, places, hasMore, veErrorMessage) { if(places.length > 0) { var shape = new VEShape( VEShapeType.Pushpin,places[0].LatLong); shape.SetTitle(places[0].Name); map.AddShape(shape); } count++; if(count<locations.length) FindLocation(locations[count]); } </script> </head> <body onload="GetMap();"> <div id=’myMap’ style="position:relative; width:800px; height:600px;"></div> <INPUT type="button" value="Find Locations" onclick="FindLocation(locations[0]);"> </body> </html> |
#1 by Anonymous on February 16, 2012 - 4:08 pm
Fantastic.
Spend too many time to find why my loop is behaving weired. And now i know how to deal with asyncronous call. or an alternative way to loop.