Hi everyone and Merry Christmas!
I'm trying to average some gps lat and long positions to smooth the output. the array is limited to two for testing purposes and would normally be in the order of 100.
The two lines fail to add correctly in the FOR loop and when I look at the values for smoothed_lat or smoothed_lon I get NaN. it seems the problem is adding the values. assigning an array element to another variable works as I have shown.
I know these are floating point numbers, am I expecting too much?
I know the values are correct in the array - position_array as can be seen.
Really struggling with this.
Cheers.
Paul.
// average the position to smooth any fluctuations
if (position_array.length == 2) {
var junk = position_array.shift();
position_array.push([float_lat, float_lon]);
} else {
position_array.push([float_lat, float_lon]);
}
var smoothed_lat = 0;
var smoothed_lon = 0;
for (var loop = 0; loop <= position_array.length; loop++){
smoothed_lat = smoothed_lat + position_array[(loop)[0]]; // This fails
smoothed_lon = smoothed_lon + position_array[(loop)[1]]; // This fails
}
smoothed_lat = position_array[0][0]; // This works
smoothed_lat = smoothed_lat / position_array.length; // gets the average
smoothed_lon = smoothed_lon / position_array.length; // gets the average