Finding a location and a custom Disambiguation box.

This Page is locked
Modified: 2007/05/18 08:01 by ViaVE Visitor
Virtual Earth offers a really powerful search API. To use it to search for a location:
function LocationSearch(searchstr) //search
{
    if (searchstr != '')
    { 
         map.Find(null,searchstr,1,searchcallback);
    }
}
The “searchcallback” is the name of a function that will execute when the result is returned, here I use it to put a custom pin on the correct location (note the results[0].LatLong not map center): This code simply is not working in v5.. results has no property

function searchcallback(results) //search returned
{
    map.Clear();
    map.AddPushpin(new VEPushpin("sPin",  results[0].LatLong, "custom.gif", "", "", "myPushpinStyle"));
}

If multiple results are returned you can use your own custom control to display them:

function myDisambiguationCallback(e) //DisambiguationCallback
{
    var r="Multiple results. Choose or refine search.<br />";
    for (x=0; x<e.length; x++)
    {
        r+="<a onclick='LocationSearch(\""+e[x].ID+"\");' href='#'>"+e[x].ID+"</a><br>";
    }
    document.getElementById('myCustomDisambiguationBox').innerHTML=r;
    document.getElementById('myCustomDisambiguationBox').style.display = "block";
}

Usage:
map.DisambiguationCallback = myDisambiguationCallback;
map.ShowDisambiguationDialog(false);