Show google map marker depending on what zoomlevel

2019-04-11 03:24发布

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!

2条回答
姐就是有狂的资本
2楼-- · 2019-04-11 03:48

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

查看更多
一纸荒年 Trace。
3楼-- · 2019-04-11 03:52

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.

查看更多
登录 后发表回答