gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:41 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com