Reputation: 797
I am trying to use an two dimensional array of points to create a polygon with Google maps api. Here is my code:
console.log(points)
mvc = new google.maps.MVCArray(points)
console.log(mvc.getArray())
console.log(mvc)
poly = new google.maps.Polygon({
paths: mvc,
strokeWeight: 2
});
//poly.setPaths(new google.maps.MVCArray(points));
Here is what console output looks like
[[44.465332670616895, 26.143829190988], [44.466098355169805, 26.1465114000029], [44.4652867292244, 26.1474555375761], [44.4646435459323, 26.1463826539702], [44.4643066375701, 26.145588720101802]]
[[44.465332670616895, 26.143829190988], [44.466098355169805, 26.1465114000029], [44.4652867292244, 26.1474555375761], [44.4646435459323, 26.1463826539702], [44.4643066375701, 26.145588720101802]]
mg { b=[5], gm_accessors_={...}, length=5, more...}
And this error:
Invalid value for constructor parameter 0: [object Object]
for the line where I try to use the MVC array to create polygon, or assign it as polygon path.
Now what am I doing wrong?
Upvotes: 4
Views: 6556
Reputation: 117334
The items of the array assigned to the path of a polygon are expected to be LatLng-objects, you must first convert the values:
for(var i=0; i < points.length; ++i){
points[i] = new google.maps.LatLng(Number(points[i][0]),
Number(points[i][1]));
}
Upvotes: 2