Recursive Find Calls

When using the AJAX version of the Virtual Earth control people have had issues making multiple find calls, one after the other. The resulting information does not always return in the order expected. The way around this issue is to use recursion. This will essentially make one call at a time and wait for one find call to finish before making another. The following code demonstrates how to do this:


      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <script src=""></script>
         var map = null;
         var count = 0;
         var locations = ["Toronto, Ontario","New York, New York","Seattle, WA"];
         function GetMap()
            map = new VEMap(‘myMap’);

         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);
<body onload="GetMap();">
<div id=’myMap’ style="position:relative; width:800px; height:600px;"></div>
<INPUT type="button" value="Find Locations" onclick="FindLocation(locations[0]);">

One thought on “Recursive Find Calls

  1. 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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s