Code example for Location

Methods: distanceTogetAccuracygetElapsedRealtimeNanos

        if (from == null) {
            return true; 
        // if new location is older than the current one, the device hasn't moved. 
        if (to.getElapsedRealtimeNanos() < from.getElapsedRealtimeNanos()) {
            return false; 
        // Get the distance between the two points. 
        float distance = from.distanceTo(to);
        // Get the total accuracy radius for both locations. 
        float totalAccuracy = from.getAccuracy() + to.getAccuracy();
        // If the distance is greater than the combined accuracy of the two 
        // points then they can't overlap and hence the user has moved. 
        return distance >= totalAccuracy;