We have been developing an ASP.NET application that works with the Google Maps API to assist in logistics and planning for a small shipping company in our area. One of the features is for the company to input a list of customers and the system will package up all the customer addresses as a series of waypoints, send it off to Google, and get back the direction information for the route.
One problem that we have been having is that many of the addresses in our database are not great and will often times are not able to be processed by Google Maps. When we do this we receive back an error code, but I would like to be able to determine which waypoint was the one to fail (that way the client can then go and fix the address in the database).
EDIT Here is a chunk of the code that handles the initialization and current error handling:
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
gdir = new GDirections(map);
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
if (document.getElementById("<%=hiddenWayPoints.ClientID %>").getAttribute("value") != '')
{
setDirections();
}
}
}
function setDirections() {
var waypoints = new Array();
var str = document.getElementById("<%=hiddenWayPoints.ClientID%>").getAttribute("value");
waypoints = document.getElementById("<%=hiddenWayPoints.ClientID %>").getAttribute("value").split(":");
gdir.loadFromWaypoints(waypoints, {getSteps:true});
}
function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
else alert("An unknown error occurred.");
}
The problem is that the LoadFromWayPoints() method in the GDirections object doesn't seem to return status based on each individual waypoint, but from just the entire list (if one fails it all fails).
The only real solution I can think of (without performing checks in other areas of the system) is to send each waypoint off to Google Maps in a separate request and check it's validity that way prior to sending off the entire waypoints list for the GDirections object, but that seems incredibly inefficient (especially when dealing with a larger set of customer locations).