[Solved] How to use android distanceBetween() method


I am confused how to distinguish starting position and end position, as location manager gives you the current position and keeps giving back new position every 5s

You already have the code available to get a new location, so you need to save the old Location and calculate distance to new location during every location update.

Location oldLoc, newLoc;
locationListener = new LocationListener() {
    @Override
    public void onLocationChanged(Location location) {
        if (oldLoc!=null) { 
            if (newLoc == null) { 
                newLoc = location; 
                // get distance 
                return; 
             } 
            // else, both not null 
            oldLoc = newLoc;
            newLoc = location;
            // get distance 
        } else { oldLoc = location; } 
    }

6

solved How to use android distanceBetween() method