开发者

How do i determine the Max Zoom Level integer for Google Maps?

Is there a way of generating the actual integer that represents the m开发者_如何学编程ax zoom level of Google Maps? In either the Static or Java API?


Yes you can generate the maximum zoom level possible for the place you are looking at as:

getMaxZoomAtLatLng(latlng:LatLng, callback:function(MaxZoomResult))

Returns the maximum zoom level available at a particular LatLng for the Satellite map type. As this request is asynchronous, you must pass a callback function which will be executed upon completion of the request, being passed a MaxZoomResult.

You can also set the maximum allowed zoom level (to prevent users from fully zooming in for instance) by using the maxZoom property of your MapOptions

The maximum zoom level which will be displayed on the map. If omitted, or set to null, the maximum zoom from the current map type is used instead.

Read everything about it here. (CTRL+F and look for "maximum zoom")


http://code.google.com/apis/maps/documentation/javascript/v2/introduction.html

Each map also contains a zoom level, which defines the resolution of the current view. Zoom levels between 0 (the lowest zoom level, in which the entire world can be seen on one map) to 19 (the highest zoom level, down to individual buildings) are possible within the normal maps view. Zoom levels vary depending on where in the world you're looking, as data in some parts of the globe is more defined than in others. Zoom levels up to 20 are possible within satellite view.

Seems like it's relatively safe to just hard code 19, but if you need the exact max for the places where 19 zoom is disallowed (military bases and whatnot) or places where 20 is allowed (not sure), I'm not sure how to determine that. Perhaps you can detect this by setZoom and then immediately calling getZoom and if the number returned from getZoom is not the one you just set, then you're in one of the non-standard locations.


Here's actual code, if it's helpful.

The accepted answer points in the right direction. The documentation you want is [right here][1].

And here's working modern ES6 code for 2019:

    /* Determine max zoom at location */
    const location = { lat: _LATITUDE_, lng: _LONGITUDE_ }

    const getMaxZoom = new google.maps.MaxZoomService()
    getMaxZoom.getMaxZoomAtLatLng(location, (response) => {
      console.log('Max zoom at this location:', response.zoom)
    })


  [1]: https://developers.google.com/maps/documentation/javascript/maxzoom
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜