When you're showing satellite imagery with our Maps API, it's often the case that you want to show the most detailed imagery available. But it's always been tricky figuring out the best zoom level for a particular location. If you don't zoom in far enough, your users won't immediately get the most detailed image available. If you zoom in too far, you might get the dreaded message "We are sorry, but we don't have imagery at this zoom level for this region", and no imagery at all.
What if there were a way to know programatically what the maximum zoom level was for any point in the world? Fortunately, now there is.
It's not easy to solve this problem naively; the world is a big place. At zoomlevel 22, there are 4 to the power of 22 potential satellite tiles -that's over17.5 trillion. The zoom level for satellite imagery that exists varies wildlyall over the world. Sydney's Bondi Beach has imagery right up to zoom level 22, whereas the centre of the Pacific Ocean only goes up to zoom level 9. (I make no accusations about whether this means the Google Maps team prefers to look at tanned, sunbathing Aussies).
But with a good search algorithm, and data based on the most frequently viewed areas of the earth, we've been able to make a search for the existence of imagery very efficient, and we are now exposing this functionality to our API developers.
The new solution is an asynchronous function which is part of theGMapType class: getMaxZoomAtLatLng. The function takesa GLatLng and returns the maximum zoom level at which imageryexists. Because the function requires a call to Google's servers (much likeGClientGeocoder.getLocations()), you must also provide a callback parameter, which is a function which will deal with the response.
GMapType
getMaxZoomAtLatLng
GLatLng
GClientGeocoder.getLocations()
callback
As an example, here's a function which will set the center of the given GMap2 object to the maximum zoom level at the given GLatLng:
GMap2
function setMaxZoomCenter(map, latlng) { map.getCurrentMapType().getMaxZoomAtLatLng(latlng, function(response) { if (response && response['status'] == G_GEO_SUCCESS) { map.setCenter(latlng, response['zoom']); } });}
As you can see, the response object contains a status code, and, if the response was successful, a zoom field containing the maximum zoom at that point.
response
status
zoom
Click on the map below, and it will zoom to the highest zoom levelavailable at the point at which you clicked.
Note that this function is only implemented for satellite imagery, and not roadmaps, whose zoom levels don't vary nearly as much. It works for both the G_SATELLITE_MAP and G_HYBRID_MAP map types. The full reference is available here.
G_SATELLITE_MAP
G_HYBRID_MAP
We hope this function makes developing with satellite imagery a simpler, easier and fuller experience. Please provide any feedback in the Maps API Google Group.
Posted by Jez Fletcher, Maps API team
Give us feedback in our Product Forums.