Code example for Location

Methods: bearingTodistanceTogetTime

0
location.setTime(time);
 
        // Calculate derived attributes from previous point 
        if (lastLocationInSegment != null
                && lastLocationInSegment.getTime() != 0) {
            long timeDifference = time - lastLocationInSegment.getTime();
 
            // check for negative time change 
            if (timeDifference <= 0) {
                Log.w(TAG, "Time difference not postive.");
            } else { 
 
                /* 
                 * We don't have a speed and bearing in GPX, make something up from the last two 
                 * points. GPS points tend to have some inherent imprecision, speed and bearing will 
                 * likely be off, so the statistics for things like max speed will also be off. 
                 */ 
                float speed = lastLocationInSegment.distanceTo(location)
                        * 1000.0f / timeDifference;
                location.setSpeed(speed);
            } 
            location.setBearing(lastLocationInSegment.bearingTo(location));
        } 
    } 
 
    /** 
     * Creates a new location