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

試著忘記壹切 提交于 2019-12-06 07:35:04

问题


I'm wondering if it's possible to set markers to be visible in a chosen zoom level for the
Google Map API v3.
I figured it's possible in the v2 of the API using the "Marker Manager" but can't find a way for the latest API.

Example:
Marker-1 -> (max_zoom:10, min_zoom:5) //will on be shown within zoom level 5-10
Marker-2 -> (max_zoom:15, min_zoom:10) //will on be shown within zoom level 10-15

As I'm developing an jQuery-plugin I only want to use the original API without add-ons.

Thanks in advance!


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/6180854/show-google-map-marker-depending-on-what-zoomlevel-youre-on

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