Show google map marker depending on what zoomlevel you're on

馋奶兔 提交于 2019-12-04 13:17:07

Supposing map is the object instanced to manage the gmap, i'd do something like this:

var zoomLevel =  map.getZoom();
if (zoomLevel>=5 && zoomLevel<=10) { 
     // call the setMarker function for the marker1
} else if (zoomLevel>10 && zoomLevel<=15) {
     // call the setMarker function for the marker2
}

Maybe u want to handler the zoom change event, if so look at this: http://code.google.com/apis/maps/documentation/javascript/events.html

You can use Marker Manager with API v3. The examples in http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markermanager/ use the most recent Maps API and they seem to work just fine.

For other options, like Marker Clusterer and Fusion Tables, see http://code.google.com/apis/maps/articles/toomanymarkers.html.

You can also do it by checking the zoom level and adding/removing markers from the map based on that, as suggested by @lucke84 in their answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!