如何在谷歌地图中设置变焦以适应圆圈?

问题描述 投票:24回答:2

我们有距离搜索过滤器。它有一个地图视窗,允许设置基本标记和一个输入文本框,允许输入公里的距离。

然后我们添加一个 循环 来在地图上显示这个距离。

如何缩放地图,使其适合圆圈?

google-maps google-maps-api-3 geometry google-maps-markers zoom
2个回答
23
投票

对于多个圆圈使用 联盟 而不是 延伸:

var bounds = new google.maps.LatLngBounds();

$.each(circles, function(index, circle){
    bounds.union(circle.getBounds());
});

map.fitBounds(bounds);

54
投票

A google.maps.Circle 拥有 getBounds() 方法,该方法返回 LatLngBounds 的圆。你可以用这个边界作为 google.maps.Map.fitBounds()

如果使用一个圆,你可以这样做。

map.fitBounds(circle.getBounds());

...在init -function的结尾。

http:/jsfiddle.netdoktormolleMHLjy。

© www.soinside.com 2019 - 2024. All rights reserved.