Google Maps API: Calculate Center/Zoom of Polyline

前端 未结 2 1579
梦毁少年i
梦毁少年i 2021-02-01 16:57

I have an overlay that is dynamically generated from user data, so I need to know how to find the center of that overlay.

Currently, I am just using the first coordinate

2条回答
  •  半阙折子戏
    2021-02-01 17:19

    Based on @tux21b,

          var bounds = new google.maps.LatLngBounds();
          polyline.getPath().forEach(function(e){//can't do polyline.getPath()[i] because it's a MVCArray
              bounds.extend(e);
          })         
          _map.fitBounds(bounds);
    

提交回复
热议问题