Look at this code:
//This "loop for" converts the GPS latitude and longitude format to Google maps format.
for (var counter1 = 0; counter1 < arrayLatitude.length; counter1++) {
//Convert ddmm.mmmm to dd.dddd latitude
var latitude1 = arrayLatitude[counter1].substr(0, 2);
var latitude2 = arrayLatitude[counter1].substr(2, 9);
var latitude3 = latitude2 / 60;
arrayLatitude[counter1] = parseFloat(latitude1) + parseFloat(latitude3);
//Convert ddmm.mmmm to dd.dddd longitude
var longitude1 = arrayLongitude[counter1].substr(0, 2);
var longitude2 = arrayLongitude[counter1].substr(2, 9);
var longitude3 = longitude2 / 60;
arrayLongitude[counter1] = parseFloat(longitude1) + parseFloat(longitude3);
}
Here I convert the GPS module coordinates to Google maps coordinates and save them to the array. Every things work good but the first cell of array arrayLatitude[0] and array arrayLongitude[0] have NaN value. This drives me crazy. Please help.
My problem is:
arrayLongitude[0] = NaN;
arrayLongitude[0] = NaN;
but other cells have the right value.
Edit: And this is the simples form of my problem:
alert(arrayLatitude[0]); //3241.1234
//This "loop for" converts the GPS latitude and longitude format to Google maps format.
for (var counter1 = 0; counter1 < arrayLatitude.length; counter1++) {
//Convert ddmm.mmmm to dd.dddd latitude
var latitude1 = arrayLatitude[counter1].substr(0, 2);
var latitude2 = arrayLatitude[counter1].substr(2, 9);
var latitude3 = latitude2 / 60;
alert(arrayLatitude[0]); //3241.1234
arrayLatitude[counter1] = parseFloat(latitude1) + parseFloat(latitude3);
alert(arrayLatitude[0]); //NaN
}
I have an array that the first cell of it is damaged so I need to put a null character in the first cell and then start the for loop from 1 instead of 0 or remove the first cell of array like this:
arrayLatitude.splice(0, 1);
arrayLongitude.splice(0, 1);
or using:
arrayLatitude.shift();
In this example I saved "" character to the first cell of array and then remove it.