I've taken a look at all the other questions but basically, I have a long list of coordinates as a string that looks like this: "42.2723998, -81.23239 ... 42.84099, -81.3990398" which I have use javascript .split(" , "); on so that its now an array called coordinate[] of strings each holding one coordinate and then using the below code:
// create a coordinate Array
var polygonCoords = [];
// creates a new LatLng
var j = 0;
var z = j + 1;
while (z < coordinate.length) {
if ((j%2) === 0) {
var co1 = parseFloat(coordinate[z]);
//document.write(coordinate[j]);
var co2 = parseFloat(coordinate[j]);
//document.write(co2);
var newLatLng = new google.maps.LatLng(co1,co2);
polygonCoords.push(newLatLng);
} else {
var co2 = parseFloat(coordinate[z]);
var co1 = parseFloat(coordinate[j]);
var newLatLng = new google.maps.LatLng(co1,co2);
polygonCoords.push(newLatLng);
}
z++;
j++;
}
but when I print out the polygonCoords array, it always returns the longitude as 0 and I've also parsed it from a string as well using parseFloat(). Also when I explicitly return the longitude by its own, it returns the actual number. I just need it to work so that I can create an array of LatLngs that I can later use as a path for a polygon.