如何在Google地图中设置缩放以适合圆圈 [英] How to set zoom to fit circle in Google Maps

查看:198
本文介绍了如何在Google地图中设置缩放以适合圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有距离搜索过滤器.它具有一个允许设置基本标记的地图视口和一个允许输入距离(以公里为单位)的输入文本框.

We have distance search filter. It has a map viewport that allow to set base marker and a input text box that allows enter distance in kilometers.

然后我们添加一个圆圈以显示该距离在地图上.

We then add a circle to show this distance on the map.

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

How can I zoom the map so it fits the circle?

推荐答案

对于多个圈子,请使用 union 而不是 extend :

For multiple circles use union instead of extend:

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

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

map.fitBounds(bounds);

这篇关于如何在Google地图中设置缩放以适合圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆