muridayo


i am using the map.FindLocation argument to geocode a bunch of addresses. from time to time, i get an error message that goes like:

"the closest match for '***address you entered***' is '***VE's assumed correct address***' If the closest match is incorrect, enter the complete address and try again."

i would want to catch this error, and add it as metadeta to the record in the database, so that i know which addresses matched with error. would anybody know how to "catch" the error message

sorry if this has been answered before, but i could not find it anywhere.

thanks




Re: how to handle error message on geocode?

Derek Chan


Okay I'm assuming your getting this because you took out the code from the interactive SDK. Understanding what is going on will help you "catch" the error.

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
<script>
var map = null;

function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
}

function FindLoc()
{
map.FindLocation(document.getElementById('txtWhere').value, onFoundResults);
}
function onFoundResults(e)
{
var results="More than one location was returned. Please select the location you were looking for:<br>";
for (x=0; x<e.length; x++)
{
results+="<a href='javascript:map.FindLocation(\""+e[x].ID+"\");'>"+e[x].ID+"</a><br>";
}
document.getElementById('resultDiv').innerHTML=results;
}
</script>
</head>
<body onload="GetMap();">
<div id='myMap' style="position:relative; width:400px; height:400px;"></div>
<div id='resultDiv' style="position:absolute; width:400px; top:408px;"></div>
<INPUT id="txtWhere" type="text" name="txtWhere">
<INPUT id="find" type="button" value="Find" name="find" onclick="FindLoc();">
</body>
</html>

Here an event was attached to the map.findLocation, called onFoundResults(). So, it gets fired whenever you execute a findlocation. Inside this function, it iterates through your results (in this case, "e") and attaches them to a gigantic string which is attached to a div tag when it is done with the results. So the key comes from this line:

results+="<a href='javascript:map.FindLocation(\""+e[x].ID+"\");'>"+e[x].ID+"</a><br>";

Just do whatever you need to with e[x], which is the result that was returned

Hope that helps,







Re: how to handle error message on geocode?

muridayo

hi derek,

thanks very much for your response. i do understand that the results are being parsed by the onFoundResults() function. however, as far as i can tell, this only provides with an e[x].ID and e[x].LatLong results. what i want to catch is the ERROR message that VE outputs when it can't find the exact address, and guesses an address for you.

is it possible to catch this error

thanks





Re: how to handle error message on geocode?

Derek Chan

Sorry I misread what you were asking for, but try to add this line to grab the text inside the error (throw it into a try/catch block):

document.GetElementById("VE_Mesage_Body").innerText;

Basically that error message is hidden inside a div tag known as VE_Mesage_Body and the id is
myMap_vemessagepanel_body so you just pull it out of that element






Re: how to handle error message on geocode?

muridayo

hi Derek,

sorry for the late response, and thanks for your answer.

i finally got around to this, and got it working based on your advice. i was not, however, able to grab this element:

document.GetElementById("VE_Mesage_Body").innerText;

and instead, used:

document.getElementById('myMap_vemessagepanel_body').innerHTML

which may be what you meant.

btw, does anybody know if there is a limitation in number of geocode actions allowed using the API

thanks





Re: how to handle error message on geocode?

Derek Chan

VE API terms of use

http://www.microsoft.com/virtualearth/control/terms.mspx

To quote:

"You are permitted to request no more than One Hundred Thousand (100,000) Transactions from the API in a twenty four hour period. A ¡°Transaction¡± means using any of the following Service functionalities (and subsets thereof), or any successor thereof or addition thereto, all as described in the Service software development kit located at http://go.microsoft.com/ LinkID=4334835 (¡°SDK¡±) including: i) Find Methods (Find, FindResult, FindResults; ii) Route Methods: (Route, RouteItinerary, and RouteSegment); and, iii) rendering eight (8) map or photographic imagery tiles (256 x 256 pixels per tile)."

and executing Find/Route/Render (if you pass a location to the render service) does result in geocoding being done.






Re: how to handle error message on geocode?

SoulSolutions

I would read those terms of use closely but also use some common sence. Clearly if you are setting up a bot to harvest the geocoding information for you database to resell then you are going to be in trouble. If you do something that clearly MS won't like then these rules are in place to shut you down. I have no relationship with MS at all but it does not make sence for them to stop some actions we all do just becouse its in the terms of use.

example we are not allowed to: "(ii) work around any technical limitations in the API;"

oops.

Clearly this is more like workaround the API logging of your transactions or hiding the copyright rather then say making it work in firefox2....I hope.

Interesting that your not allowed to print the birdseye images at all, didn't know that.

John.






Re: how to handle error message on geocode?

Lyle Karstensen

For anyone who just wants to be able to supress the error that is returned by the GeoCode here is what I did... I am using V5 of the API and calling the objGeoMap.Find() function.

<style type="text/css">

#myGeoMap_vemessagepanel{ <<<< Replace myGeoMap with what ever the ID you used in the DIV that holds the map
visibility:hidden;
display: none;
}
</style>