How to get LatLngBounds of feature polygon geometry in google maps v3?

前端 未结 3 1275
耶瑟儿~
耶瑟儿~ 2020-12-18 19:24

I have a lot of polygonal features loaded with loadGeoJson and I\'d like to get the latLngBounds of each. Do I need to write a function that iterates through every lat long

3条回答
  •  一个人的身影
    2020-12-18 20:13

    Here's another solution for v3 Polygon :

    var bounds = new google.maps.LatLngBounds();
    
    map.data.forEach(function(feature){
      if(feature.getGeometry().getType() === 'Polygon'){
        feature.getGeometry().forEachLatLng(function(latlng){
          bounds.extend(latlng);
        });
      }
    });
    

提交回复
热议问题