javascript - 略微扩展谷歌地图的边界

标签 javascript google-maps google-maps-api-3

我正在使用 map.fitbounds 来适应我在 map 视口(viewport)中设置的所有标记,但标记正好靠在视口(viewport)的两侧,我想缩小一点。

我试过了

map.setZoom(map.getZoom() - 1); 

但它向外移动太多,似乎随着视口(viewport)缩放到顶部。 理想情况下,我想模拟滚动鼠标滚轮时发生的情况 1 单击以缩小一点。

您可以在此处查看存在问题的示例文件。

http://dl.dropbox.com/u/1367679/MapLifeEvents.html

如您所见,理想情况下您只想稍微出去一点以显示基地的标记。

最佳答案

谷歌地图中的缩放级别不是连续的,因此您无法按照您想要的方式调整级别。您可以做的是创建一个 LatLngBounds object并使用它的扩展方法你有标记,最后使用 panToBounds method of map使 map 适合您的标记。

在最后一个方法的描述中,您将看到以下内容

Pans the map by the minimum amount necessary to contain the given LatLngBounds.It makes no guarantee where on the map the bounds will be, except that as much of the bounds as possible will be visible. The bounds will be positioned inside the area bounded by the map type and navigation (pan, zoom, and Street View) controls, if they are present on the map. If the bounds is larger than the map, the map will be shifted to include the northwest corner of the bounds. If the change in the map's position is less than both the width and height of the map, the transition will be smoothly animated.

希望对你有帮助

关于javascript - 略微扩展谷歌地图的边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6758772/

相关文章:

javascript - 一个(有点晦涩的)Javascript 继承问题

javascript - 让你的 NPM 包支持多个版本的对等依赖

google-maps - 谷歌地图使用 Maptiler 平铺整个世界

c# - Google map - ASP.Net 中的简单方法?

javascript - 离开页面后返回谷歌地图 V3 上的标记

javascript - 是否可以使用图像或 CSS 渐变来填充 Google map 中的水域?

Javascript函数无法触发onclick

javascript - 如何组合从不同的 JS 文件对 Ajax 数据库的多个调用

javascript - Google map 信息框位置位于标记旁边而不是位于标记上方

javascript - 当 MapStyle 改变时,谷歌地图改变图标标记