private static float distanceBetween(Location location1, Location location2) {
    double earthRadius = 3958.75;
    double latDifference = Math.toRadians(location2.getLatitude() - location1.getLatitude());
    double lonDifference = Math.toRadians(location2.getLongitude() - location1.getLongitude());
    double a = Math.sin(latDifference/2) * Math.sin(latDifference/2) +
        Math.cos(Math.toRadians(location1.getLatitude())) * Math.cos(Math.toRadians(location2.getLatitude())) *
            Math.sin(lonDifference/2) * Math.sin(lonDifference/2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    double dist = Math.abs(earthRadius * c);

    int meterConversion = 1609;

    return (float) (dist * meterConversion);
  }
private static float distanceBetween(Location location1, Location location2) {
    double earthRadius = 3958.75;
    double latDifference = Math.toRadians(location2.getLatitude() - location1.getLatitude());
    double lonDifference = Math.toRadians(location2.getLongitude() - location1.getLongitude());
    double a = Math.sin(latDifference/2) * Math.sin(latDifference/2) +
        Math.cos(Math.toRadians(location1.getLatitude())) * Math.cos(Math.toRadians(location2.getLatitude())) *
            Math.sin(lonDifference/2) * Math.sin(lonDifference/2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    double dist = Math.abs(earthRadius * c);

    int meterConversion = 1609;

    return (float) (dist * meterConversion);
  }
private static float distanceBetween ( Location location1 , Location location2 ) { double earthRadius = 3958.75 ; double latDifference = Math . toRadians ( location2 . getLatitude ( ) - location1 . getLatitude ( ) ) ; double lonDifference = Math . toRadians ( location2 . getLongitude ( ) - location1 . getLongitude ( ) ) ; double a = Math . sin ( latDifference / 2 ) * Math . sin ( latDifference / 2 ) + Math . cos ( Math . toRadians ( location1 . getLatitude ( ) ) ) * Math . cos ( Math . toRadians ( location2 . getLatitude ( ) ) ) * Math . sin ( lonDifference / 2 ) * Math . sin ( lonDifference / 2 ) ; double c = 2 * Math . atan2 ( Math . sqrt ( a ) , Math . sqrt ( 1 - a ) ) ; double dist = Math . abs ( earthRadius * c ) ; int meterConversion = 1609 ; return ( float ) ( dist * meterConversion ) ; }
Returns the distance between the two locations in meters.
Adapted from: http://stackoverflow.com/questions/837872/calculate-distance-in-meters-when-you-know-longitude-and-latitude-in-java
Returns the distance between the two locations in meters . Adapted from : http : // stackoverflow . com / questions / 837872 / calculate - distance - in - meters - when - you - know - longitude - and - latitude - in - java