The ability to search for locations is essential in all versions of Bing Maps. In version 2 this was accomplished using the Bing Maps Search Manager. This required accessing content outside of main Web page’s domain. Listing 17 shows a search in version 2.
function DoFind()
{
var where = document.getElementById("WhereText").value;
VE_SearchManager._ResetPaging();
VE_SearchManager._CancelAllRequests();
VE_SearchManager.searchPage="http://local.live.com/search.aspx";
VE_SearchManager._DoSearch(where, where);
}Listing 17. Searching for locations in version 2
This search functionality is no longer supported, as the local.live.com URL no longer supports query strings. Versions 3 and 4 use the Find, FindNearby, and FindLocation functions, as shown in Listing 18, Listing 19, and Listing 20, respectively.
map.Find(what,where, index, callback);
Listing 18. The Find function in versions 3 and 4
map.FindNearby(what, callback);
Listing 19. The FindNearby function in versions 3 and 4
map.FindLocation(where, callback);
Listing 20. The FindLocation function in versions 3 and 4
Version 5 combined these methods into the Find method. This method has many more options than its predecessors. The code in Listing 21, Listing 22, and Listing 23 are are equivalent to the Find, FindNearby, and FindLocation functions shown in Listing 18, Listing 19, and Listing 20, respectively.
map.Find(what, where, null, null, null, null, null, null, null, null, callback);
Listing 21. The Find function in versions 5 and 6.2
map.Find(what, null, null, null, null, null, null, null, null, null, callback);
Listing 22. The Find (nearby) function in versions 5 and 6.2
map.Find(null, where, null, null, null, null, null, null, null, null, callback);
Listing 23. The Find (location) function in versions 5 and 6.2
The other parameters in the Find method allow for extensive control over how the search is performed. You can, for example control whether pushpins are automatically created, or whether the map control displays a disambiguation dialog box if more than one result is returned.