Handling Geocoding Error Screens in Virtual Earth

In the Virtual Earth AJAX control, there are certain screens that are somewhat hard to capture and control. We pride ourselves on the level of control we give our users, so here’s a little tidbit to hopefully help you retain what hair is left atop your head. I posted an entry a while back called Geocoding with Virtual Earth that should get you this far; but, what should you do when you get a box like this and you don’t want your users to see it?

image

The crux of the issue is using the “what” and “where” properties together in the VEMap.Find() method. When you do this, you’re actually using a different geocoding engine than you would be if you were to leave the “what” field blank using the same VEMap.Find() method.

So, how do you work around this?

  1. You could do two calls – one for geocoding using VEMap.Find() and another for the “what” and “where,” but only extract the “what” results. This will use the new geocoding engine and won’t show these messages.
  2. Set the ShowMessageBox property on the map to false before making the what/where Find call.  This property is not documented (thus, not totally tested); however, it’s a simple property that just prevents message boxes from being displayed in the control. 

So, your code would look something like this (for solution 2):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Geocoding</title>
<!-- saved from url=(0014)about:internet -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="https://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
<script type="text/javascript">
var map = null;
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
map.ShowMessageBox = false;
}
function FindLoc()
{
try
{
map.Find(null, txtWhere.value);
}
catch(e)
{
alert(e.message);
}
}
</script>
</head>
<body onload="GetMap();">
<div id='myMap' style="position:relative; width:800px; height:600px;"></div>
<INPUT id="txtWhere" type="text" name="txtWhere">
<INPUT id="find" type="button" value="Find" name="find" onclick="FindLoc();">
</body>

</html>

Now, the thing to remember is that you’re suppressing the error so the exciting thing that happens is….nothing! But, hey, that’s what you want! You want control? You got it. Just make sure that if you suppress the error you throw one up of your own otherwise your users may sit and blankly stare at your map waiting for something to happen.

CP