One year ago, the Google Maps API development team released a small but pretty neat improvement to their Geocoding API: the ability to get the response’s accuracy level for a given address.
This feature enables applications to modify their zoom level according to the precision of the address that’s being geocoded, for example, “Paris” at the city zoom level, but “1 rue Royale, 75008 Paris” at the much more precise street address zoom level.
What the Google geocoder actually outputs (see reference) is a value between 1 and 8. And the GMaps zoom level is an integer between 1 and 19. So the question is: given a geocoding accuracy, which zoom level should I use to display the place? I didn’t find any answer to that question on the web so I decided to make up my own correspondence between the two scales. Any such correspondence is bound to be imperfect since two different cities can have very different sizes, however the method usually outputs a decent result.
var tabAccuracy = new Array(2,4,6,10,12,13,16,16,17);
function showAddress(address) {
if (geocoder) {
geocoder.getLocations(address,
function(response) {
if(response.Status.code!=200){
alert('"' + address + '" not found');
} else {
place = response.Placemark[0];
accuracy = place.AddressDetails.Accuracy;
map.setCenter(new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]), tabAccuracy[accuracy]);
}
}
);
}
}
I calibrated the association on a few cities such as Paris, NYC and San Francisco, and I was a bit conservative to ensure that people with small screens still get the picture. Let me know if you find this scale useful.