I fetch my current heading in the compute(info) function:
function compute(info) {
heading_rad = info.currentHeading;
if( heading_rad < 0 ) { //convert to 0 to 2pi (0-360)
heading_rad = 2*Math.PI+heading_rad;
}
}
From what I understood this SHOULD get the heading based on gps if speed is high enough, but during running (12km/h) it was also influenced with how I held my watch. If I turned it 90 degrees (from havin my arm in front to my arm at my side) the heading returned differed greatly (but didn't seem to correspond to the 90 degrees?). But in general this seemed to fluctuate a lot!
Am I missing something here? (I read something about needing to call Activity.getInfo() to get the current info, but I assume this is done before compute() actually?
The heading between a start and target is calculated using:
function getHeadingRadNormal(lat1, lon1, lat2, lon2){
var dLong = lon2 - lon1;
var y = Math.sin(dLong) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLong);
var brng = Math.atan2(y, x); //-pi to po
if(brng<0){
brng = 2*Math.PI+brng; //0 to 360
}
return brng;
}
And that seems to work fine (this is constant value and seems to be correct), when displaying the indicator on the watch I simply subtract my current heading from the target point heading: brng-heading_rad but that is messed up by the weird currentHeading
Is it better just to use the last 2 latlon points? (Or a larger buffer, can imagine just the last 2 points also gives a large uncertainty).