Address Search
You can access this API address service via the AGSearch object. Use AGSearch.search() to convert a string address into search result that contains top 20 matched result. This method takes as parameters a string address to convert, and a callback function to execute upon retrieval of the address.
In this example, we search addresses, add a marker at that points.
Search
//for AGSearch
oSearch = new AGSearch();
oCache = new AGSearchCache();
oSearchCache = new AGSearch(oCache);
function search()
{
var strSearch = document.getElementById("txtSearch").value;
if(strSearch == "")
{
alert("Search string should have some text");
return;
}
var bCache = document.getElementById("cbCache").checked;
if(bCache)
{
oSearchCache.search(strSearch,callbackSearchedResult);
}
else
oSearch.search(strSearch,callbackSearchedResult);
}
var arrMarkers = new Array();
function callbackSearchedResult(oResponse)
{
//alert(oResponse);
var arr = oResponse.SearchResults;
var str = "";
var oCoords = null;
var marker = null;
if (arr != null) {
for (var i = 0; i < arr.length; i++) {
str += arr[i].ResultItem.Description + " \n";
oCoords = new AGCoord(parseFloat(arr[i].ResultItem.Latitude), parseFloat(arr[i].ResultItem.Longitude));
marker = new AGMarker(oCoords);
agmap.addOverlay(marker);
arrMarkers.push(marker);
}
} else {
alert('No results found.');
}
}