Android Distance Calculate distanceBetweenTwoPoints(double lat1, double lng1, double lat2, double lng2)

Here you can find the source of distanceBetweenTwoPoints(double lat1, double lng1, double lat2, double lng2)

Description

distance Between Two Points

Declaration

public static double distanceBetweenTwoPoints(double lat1, double lng1,
            double lat2, double lng2) 

Method Source Code

//package com.java2s;

public class Main {
    public static double distanceBetweenTwoPoints(double lat1, double lng1,
            double lat2, double lng2) {
        int r = 6371; // average radius of the earth in km
        double dLat = Math.toRadians(lat2 - lat1);
        double dLon = Math.toRadians(lng2 - lng1);
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
                + Math.cos(Math.toRadians(lat1))
                * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2)
                * Math.sin(dLon / 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        double d = r * c;
        return d;
    }/*from w  w w. ja va2 s .  c  o m*/
}

Related

  1. getDistance(double lat1, double lon1, double lat2, double lon2)
  2. dist(PointF p1, PointF p2)
  3. distance(int q1, int r1, int q2, int r2)
  4. distanceBetweenTwoLatLongs(Location oldLocation, Location newLocation)
  5. distanceInMeters(float distance)
  6. KmToMiles(int distance)
  7. getTempsTrajetBus(int distance)
  8. getTempsTrajetPied(int distance)
  9. hammingDistance(String sourceHashCode, String hashCode)