
Changes for Finding a Location
VEMap.FindLocation and VEMap.FindNearby have been merged into a single VEMap.Find method. The VEFindResults and VESearchResult classes in version 4.0 have been replaced with the FindResult class and a new VEPlace class.
Using the consolidated Find method, Version 5.0 still allows you to search for both "what" and "where" in addition to providing levels of customization such as disabling the autozoom and disambiguation box.
Making Find Calls
If you need to duplicate a simple VEMap.FindNearby or a VEMap.FindLocation from version 4.0:
Listing 10: A simple FindNearby call in Version 4.0
Listing 11: A simple FindLocation call in Version 4.0
The equivalent methods in Version 5.0 are straightforward:
Listing 12: A FindNearby equivalent call in Version 5.0
Listing 13: A FindLocation equivalent call in Version 5.0
Likely you will want to consume the results returned from your search. In version 4.0 you would add the callback parameter at the end of your method:
map.FindNearby(what,callback)
Listing 14: A FindNearby with callback in Version 4.0
map.FindLocation(where,callback)
Listing 15: A FindLocation with callback in Version 4.0
Due to the vast array of customization options in version 5.0, many nulls will need to be inserted to accommodate for the callback parameter which occurs at the end of the VEMap.Find method.
map.Find(what,null,null,null,null,null,null,null,null,null,callback);
Listing 16: A FindNearby with callback in Version 5.0
map.Find(null,where,null,null,null,null,null,null,null,null,callback);
Listing 17: A FindLocation with callback in Version 5.0
Finally, a VEMap.Find call in version 4.0 was a combination of both VEMap.FindNearby and VEMap.FindLocation methods.
map.Find(what,where,index,callback);
Listing 18: A Find with callback in Version 4.0
Version 5.0 easily puts them together in its own VEMap.Find correspondent.
map.Find(what,where,null,null,null,null,null,null,null,null,callback);
Listing 19: A Find with callback in Version 5.0
Processing the Find Callback
In Version 4.0, the Map.Find callback returned either an array of VESearchResult objects or an array of VEFindResults objects , depending on what parameters were initially passed to make the Map.Find call.
function FindElvis()
{
Map.Find(‘elvis’,’Las Vegas,NV ’,’1’,onFoundResults);
}
function onFoundResults(findResults)
{
var results="Find Results:\n";
for (r=0; r < findResults.length; r++)
{
results += findResults[r].Name + ", ";
results += findResults[r].Description + ": ";
results += findResults[r].Phone + "\n";
}
alert(results);
}
Listing 20: Sample code for processing the callback in Version 4.0
In V5, the information sent to the callback has been split into four parameters: Shapelayer, VEFindResult[], VEPlace[], HasMore. Also to note is that the VEFindResult and VEPlace parameters that are returned are actually arrays even if only one result is returned starting at the [0] index. The ShapeLayer parameter is only used if you used the Find parameter indicating that your results should be added to a specific shape layer rather than the general map.
A typical find callback skeleton would be:
function callback(ShapeLayer,FindResultArray,PlaceArray,HasMore)
{
// Consume the results here
}
Listing 21: processing the callback in Version 5.0
Putting it all together, here’s a sample VEMap.Find call that displays the results of a "what and where" search in an alert box.
map.Find(“Microsft”,”Seattle”,null,null,1,null,null,null,null,null,OnFoundResults);
function OnFoundResults(ShapeLayer,FindResult,Place,HasMore)
{
alert(ShapeLayer.GetTitle() + “ , ” + ShapeLayer.GetDescription() + “ , “ + FindResult[0].Name + “ , “ + Place[0].Name + " , "+Place[0].LatLong + “ , “ + HasMore);
}
Listing 22: Sample Find call with Callback in Version 5.0
Figure 3: Sample Version 5.0 VEMap.Find() Callback Result
Note that depending on your Find call parameters, the find results and place results parameters may be null.