Question

I found an answer for how to get the latitude and longitude for each point of the polygon here:

Polygon Drawing and Getting Coordinates with Google Map API v3

This appeared to work when I implemented it, however is no longer working, and I get the error:

"Error: TypeError: polygon.overlay.latLngs.b is undefined"

This is my code:

function polygonPoints(polygon) {
    var polygonPointsArray = [];

    $.each(polygon.overlay.latLngs.b[0].b, function(key, latlng){
            var lat = latlng.d;
            var lon = latlng.e;

            polygonPointsArray.push(lat+' '+lon); //do something with the coordinates
    });
}

Any help would be greatly appreciated.

Thanks

Matt

Was it helpful?

Solution

That failed because polygon internal structure changed which happens from time to time.

How to get latitude and longitude of polygon points is described in this google example.

OTHER TIPS

I had this problem as well - the quick fix for me was to change

$.each(polygon.overlay.latLngs.b[0].b, function(key, latlng){

to

$.each(polygon.overlay.latLngs.j[0].j, function(key, latlng){
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top