谷歌地图的多段线边界

Polyline bounds for Google Maps

本文关键字:边界 段线 谷歌地图      更新时间:2023-09-26

如何让这个谷歌地图调整到多段线边界的大小?

http://goo.gl/hjOcAx

我认为我使用这个是正确的:

var bounds = new google.maps.LatLngBounds();
    decodedPath.getPath().forEach(function(LatLng) {
    bounds.extend(LatLng);
});
map.setBounds(bounds);

但我也认为我把它放错了地方。

  1. decodedPath是一条路径(不是多段线),并且没有方法getPath()。用途:

    decodedPath.forEach(function(LatLng) {
       bounds.extend(LatLng);
    });
    
  2. 没有方法setBounds(),而是使用fitBounds()