Google Maps API Tutorial - Did You Mean?© 2007 Mike Williams |
"Did You Mean?"The maps.google.com page will ask a "Did you mean?" question in response to an address search under certain circumstances. You might possibly want to offer the same functionality within the API.Note: The API geocoder is quite different from the maps.google.com geocoder. Situations which cause the conditions which provoke a "Did you mean?" in one geocoder will not usually cause those conditions in the other geocoder. Multiple HitsOne condition which provokes the question is when the geocoder returns more than one Placemark in response to the query.
To detect this situation with the API geocoder, simply test whether result.Placemark.length is greater than 1. Here's an example The API geocoder doesn't often return multiple results. Janitell Rd, Colorado Springs, CO is one example address which produces three results in the API geocoder. I don't know of any addresses that produce multiple results in both the API geocoder and the maps.google.com geocoder. Potential Pitfalls
Significantly Different AddressThe geocoder may occasionally return an address which is sufficiently different from the requested address to be worth asking the "Did you mean?" question.For example, if you search for 20 Rocci Rowed Gilford,NH, the API geocoder will return a single result for 20 Rocky Rd, NH 03249, USA, which you might consider to be sufficiently different to be worth querying. This circumstance is much harder to test for. The returned address will often look very different from the query just because the geocoder converts the address into a standard format. In this case, the fact that "Gilford" has been replaced by the zip code "03249"; and the fact that ",USA" has been added; should not be considered to be "significant" differences in the address. I reckon that it's impractical to compare anything other than the house number and street. To go any further would require some fairly sophisticated AI to handle all the possible valid variations that might be used, and you'd almost need to write your own geocoder to check if "Gilford" actually is zip code "03249". My strategy for matching the street is to
I've not done an awful lot of testing with this. |