Here you can find the source of distanceBetweenTwoLatLongs(Location oldLocation, Location newLocation)
public static double distanceBetweenTwoLatLongs(Location oldLocation, Location newLocation)
//package com.java2s; import android.location.Location; import android.util.Log; public class Main { public static double distanceBetweenTwoLatLongs(Location oldLocation, Location newLocation) { double distance = 0; if (newLocation != null && oldLocation != null) { distance = oldLocation.distanceTo(newLocation); // in meters } else {//from ww w.j a v a 2 s.c om if (newLocation == null) { Log.e("newLocation is null", ";;"); } if (oldLocation == null) { Log.e("oldLocation is null", ";;"); } } Log.e("distanceBetweenTwoLatLongs", "" + distance / 1000); return distance / 1000; // Convert meters to KM } }