͢bts
͢bts

Reputation: 695

How do I detect when a user is at the maximum zoom level? (google maps v3)

I am clustering my markers together. When a user zooms in to the highest level I need to break the clusters up so that the user can view information for individual items. Given that the number of zoom levels is different depending on the type of map used and that 'maxZoom' may have been explicitly set in mapOptions, how do I detect when the user cannot zoom any further (i.e. the zoom slider is at its highest point)? Is there just a zoom level number I can use for this (21 perhaps)? Or is this number variable depending on different scenarios? What would these scenarios be?

I do not need to know this value prior to zooming in: only when the user REACHES the max level.

Upvotes: 3

Views: 2005

Answers (3)

slawekwin
slawekwin

Reputation: 6310

google maps api have a service for that, you could use it like that:

(new google.maps.MaxZoomService()).getMaxZoomAtLatLng(map.getCenter(), function(response) {
    if (response.status != google.maps.MaxZoomStatus.OK) {
      alert("Error in MaxZoomService");
      return;
    } else {
      if (map.getZoom() >= response.zoom) {
          //do sth with your clusterer
          //probably markerClusterer.setMaxZoom(response.zoom - 1);
          //or markerClusterer.setMap(null);
      }
    }
});

EDIT: there is also a solution I found in markerclusterer.js (from google maps utility library), but it recently started to cause errors and I am not sure if it is reliable:

map.mapTypes[map.getMapTypeId()].maxZoom;

Upvotes: 7

duncan
duncan

Reputation: 31930

Most city maps will zoom to 18, but some go beyond that, and there are isolated satellite views up to level 23.

Upvotes: 0

JHolyhead
JHolyhead

Reputation: 984

From a quick test, looks like z=19 is the most zoomed in before you get to street view level. Tested in a couple of countries, it hasn't changed.

Upvotes: 0

Related Questions