开发者

Google Static Map API how to specify max zoom level

开发者 https://www.devze.com 2023-02-22 03:12 出处:网络
We have a report that shows where 2 markers are on a map, works great except when the markers are next to each other it zooms in to the highest level of zoom.

We have a report that shows where 2 markers are on a map, works great except when the markers are next to each other it zooms in to the highest level of zoom.

We want the min zoom to be open, but set the max zoom to a certain level. I have looked through the Google Static Map documentation, and cant see where to do it.

Does anyone 开发者_高级运维know if this is possible using the static map api?

Cheers.


Google does not have that feature in place. Here is a feature request:

Issue 3909 http://code.google.com/p/gmaps-api-issues/issues/detail?id=3909

Please vote!


Well it is sort of not straight forward to get it with static maps. You can omit specifying the zoom and hope google will choose what it thinks best.

Anyway this is how I got rid of it. I had my own zoom up / zoom down buttons to show up next to the map image. Upon click, I increase or decrease the current zoom value and reload the map image.

I know it's not pretty, but it gets the job done.


I have not tried that for static maps but it works for me in normal map:

google.maps.event.addListener($map, 'zoom_changed', function(){
if($map.getZoom()<4){$map.setZoom(4);}
if($map.getZoom()>14){$map.setZoom(14);}
});

Here I am limiting both max and min zoom.

Hope it helps

K


http://maps.google.com/staticmap?markers=-21.7164,35.4384&size=640x640&key=your-api-key&format=png8&maptype=roadY&zoom=8

Note the zoom querystring parameter


I found the following code from this URL: http://code.google.com/apis/maps/documentation/javascript/events.html

google.maps.event.addListener(marker, 'click', function() { map.setZoom(8); });

Instead of adding listener, you could do document.onload(function() { map.setZoom(8));

0

精彩评论

暂无评论...
验证码 换一张
取 消