Currently I save coordinates for an polygon in this format into database:
[52.32527, 12.99683],[52.32191, 13.76587],[52.45936, 13.79333],[52.68637, 13.39233],[52.69636, 13.03528]
Later I fetch an array of the polygons from database, so I have something like $polygon_array[$key]['coordinates'] where the latlngs are a string.
With PHP adding a polygon to map works:
But adding to map without PHP does not work neither throws an error:
var polygon_array = JSON.parse( '' ); // transfer PHP Array to Javascript
jQuery.each(polygon_array, function (index, value) {
coords = polygon_array[index]['coordinates'];
L.polygon([coords]).addTo(map);
});
I think the problem is that Javascript handles the coords as string.
My Questions: How can I use entries from database for a valid latlngs parameter?
Isn't there an easy way to use the format above?
0 comments:
Post a Comment