In Javascript, I have two arrays, called latitude and longitude, that have appropriately long and lat values (as strings originally from an asp.net controller, I got them from parsing an XML feed).
What I want to do is create a new array, called points, that has the lat/lng values in it, so I can display those values on a map. Here is what I thought should work, but does absolutely nothing:
var points=new Array();
for(var i=0; i<latitude.length; i++){
points=new google.maps.LatLng(latitude[i], longitude[i]);
}
the latitude and longitude arrays are the same length, I don’t think thats a problem. Thanks, Amanda
You are not adding elements to the array, but instead assigning a new
LatLngobject to thepointsvariable in each loop iteration (points = new). To add elements to the array, either subscript the array position (points[index] = value) and assign the object to it:Or use
Array#push():