中心/设置地图缩放以覆盖所有可见的标记? [英] Center/Set Zoom of Map to cover all visible Markers?

查看:135
本文介绍了中心/设置地图缩放以覆盖所有可见的标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在地图上设置了多个标记,我可以静态设置缩放级别和中心,但我想要的是覆盖所有标记并尽可能缩放,使所有市场都可见

可用的方法如下:


I am setting multiple markers on my map and I can set statically the zoom levels and the center but what I want is, to cover all the markers and zoom as much as possible having all markets visible

Available methods are following

setZoom(zoom:number)

and

setCenter(latlng:LatLng)

Neither setCenter supports multiple location or Location array input nor setZoom does have this type of functionality

解决方案

You need to use the fitBounds() method.

var markers = [];//some array
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markers.length; i++) {
 bounds.extend(markers[i].getPosition());
}

map.fitBounds(bounds);

Reference:

这篇关于中心/设置地图缩放以覆盖所有可见的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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