Skip to content Skip to sidebar Skip to footer

Adding Google.maps.latlng To An Array Within A Loop

This is my code to draw a polygon on a map... which doesnt work. Please tell me what I'm doing wrong. If I add points manually like this: points.push(new google.maps.LatLng(51.3502

Solution 1:

I'm not sure what you mean by "adding points manually", but I think the problem is that the ajax call is asynchronous. So, you're caling "$.ajax(...)" and then falling right through to the code that creates Area before your points array has anything in it: the asynchronous call to your success function hasn't happened yet.

Try rearranging your code so you create Area and do the setMap(map) call in your success function, right after the loop.

Post a Comment for "Adding Google.maps.latlng To An Array Within A Loop"