GMaps Geocoder Accuracy and Zoom level
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.
February 20th, 2008 at 6:53 am
I guess zoom level depends on your map size as well. If your map is too little you need to zoom out. With big map you can zoom in more.
February 23rd, 2008 at 6:07 am
[…] the map and set the zoom level. My problem was to find right zoom level for given location. I found one blog post that describes the solution but I wasn’t very happy with […]
February 23rd, 2008 at 6:18 am
Hi, I think I found the right formula. It takes into account map size and (hopefully) size of the cities:
http://throwless.wordpress.com/2008/02/23/gmap-geocoding-zoom-level-and-accuracy/
February 24th, 2008 at 3:39 am
Yeah, map size was what I meant with “being conservative to ensure that people with small screens still get the picture” (Here at MapMyGlobe we have a full-screen map).
Can you explain your formula a bit, though? In particular, what’s the range parameter? It’s not mentionned in the documentation.
March 6th, 2008 at 6:25 am
Hello again, I just implemented another, more accurate and even easier way of finding right zoom level:
http://throwless.wordpress.com/2008/03/06/zoom-level-finding-the-right-one/
November 25th, 2008 at 11:27 am
Works perfectly! Thanks a million!!!