javascript - Converting string of coordinates to lat long array for google maps api v3 returning longitude as 0 -


i've taken @ other questions basically, have long list of coordinates string looks this: "42.2723998, -81.23239 ... 42.84099, -81.3990398" have use javascript .split(" , "); on array called coordinate[] of strings each holding 1 coordinate , using below code:

// create coordinate array     var polygoncoords = [];     // creates 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 print out polygoncoords array, returns longitude 0 , i've parsed string using parsefloat(). when explicitly return longitude own, returns actual number. need work can create array of latlngs can later use path polygon.

ok, i've fixed it, somehow when grabbed longitude kml file, in form of 0 -81.290390... , whenever parsed float, recognize 0 instead of -81.293848. done properly, , printing out correct floats.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -