LatLng from Google Maps Polygon getPath()
var polygonBounds = polygon.getPath();
var bounds = [];
for (var i = 0; i < polygonBounds.length; i++) {
var point = {
lat: polygonBounds.getAt(i).lat(),
lng: polygonBounds.getAt(i).lng()
};
bounds.push(point);
}
When you call Polygon.getPath()
api-doc, the return is an MVCArray
api-doc of LatLng
instances that represent the first path of the Polygon
. You can directly get to the members of the MVCAarray
in two ways:
- Call
MVCAarray.getArray
, which will return the underlying JavaScriptArray
that containsLatLng
members. - Use
MVCArray.getAt( index )
, which will return whatever is at that index in theMVCArray
(aLatLng
in this case). This provides you a way to setup a JavaScriptfor
loop to iterate over the members of the array.
You can also indirectly work with the members of the MVCArray
by using the forEach(callback:function(*, number))
function. In this case, you must pass a callback function that accepts two parameters:
- The actual member element of the
MVCArray
. - The array index where that element is located.