What means bearingFromStart?

Hi,

I want to implement an indicator in my datafield in which direction the beginning of the activity is. I searched in the activity.info field and found bearingFromStart. The api doc says:

bearingFromStart is the direction of desired track from start of navigation to destination in radians. This is only dependent on your location when the Course is set, and it is not dependent on where you may have moved to.

Is this the information I can use?
  • It is my understanding that this will only work on devices with navigation support, and will only be non-null if a course is currently being navigated.

    Travis
  • Hi Travis, this is not what I want to do. I probably have to calculate it for myself. What I can do is, store the first GPS coordinate which represents the start point. Furthermore I can grab the current GPS coordinate. Now I can calculate the angle of this line in relation to North.

    The only problem now is the math...
  • Here's a very simple function I use that's based on something planetScooter posted years ago. It doesn't account for the curvature of the earth, but works well and I use it in a few things. (lat/lon in degrees)

    //
    // distance between two location (meters)
    //
    function computeDistance(lat1, lon1, lat2, lon2) {
    var mlat,mlon;
    var dx, dy, distance;

    mlat = (lat1 + lat2) / 2 * 0.01745;
    dx = 111.3 * Math.cos(mlat) * (lon1 - lon2);
    dy = 111.3 * (lat1 - lat2);
    distance = 1000 * Math.sqrt(dx * dx + dy * dy);
    return distance;
    }


    I also do direction, and for that, I do it with compass points, and just compare the two lat/lons and see the general direction to go to get between the two (N,NE,E,SE,S,SW,W,NW), but you can probably get the angle from the above function.
  • Hi Jim,

    cool, if I have dx and dy I can calculate the angle. I assume that the y axis points to north, isn't it?

    Edit: Probably: Alpha = 90 - tan(dy/dx)
  • I'll see if this bit of API documentation can be clarified further.