Based on the Google Maps JavaScript API v3 documentation, google.maps.Polygon class’s getPath() function returns an MVCArray. In a straightforward case, a Polygon’s path can be a single array of LatLngs that are converted to the MVCArray type upon being passed into the google.maps.Polygon class’s setPath() function.
The above case is what I’m dealing with currently. I pass in an array of LatLngs, and return (what I assume is) an MVCObject when I call getPath() on my Polygon object. My question is: How do I convert this MVCObject back into a single array of LatLngs that form the Polygon’s shape? Is there some built in Google Maps API v3 way that I’m missing? I feel like there has to be some sort of obvious built in conversion function or something in the API that’s eluding me.
Any help would be appreciated.
When you call
Polygon.getPath()api-doc, the return is anMVCArrayapi-doc ofLatLnginstances that represent the first path of thePolygon. You can directly get to the members of theMVCAarrayin two ways:MVCAarray.getArray, which will return the underlying JavaScriptArraythat containsLatLngmembers.MVCArray.getAt( index ), which will return whatever is at that index in theMVCArray(aLatLngin this case). This provides you a way to setup a JavaScriptforloop to iterate over the members of the array.You can also indirectly work with the members of the
MVCArrayby using theforEach(callback:function(*, number))function. In this case, you must pass a callback function that accepts two parameters:MVCArray.