Java Distance Calculate distanceBetween(double latitude1, double longitude1, double latitude2, double longitude2)

Here you can find the source of distanceBetween(double latitude1, double longitude1, double latitude2, double longitude2)

Description

distance Between

License

Apache License

Declaration

public static double distanceBetween(double latitude1, double longitude1, double latitude2, double longitude2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static double distanceBetween(double latitude1, double longitude1, double latitude2, double longitude2) {
        double distance = 0.0;
        double deltaLat = Math.toRadians(latitude2 - latitude1);
        double deltaLon = Math.toRadians(longitude2 - longitude1);
        latitude1 = Math.toRadians(latitude1);
        latitude2 = Math.toRadians(latitude2);
        longitude1 = Math.toRadians(longitude1);
        longitude2 = Math.toRadians(longitude2);

        double earthRadius = 6371 * 1000;
        double a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2)
                + Math.cos(latitude1) * Math.cos(latitude2) * Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        distance = earthRadius * c;/*from  w  ww .j  a v a 2 s  . co m*/
        return distance;
    }
}

Related

  1. distance_to_endpoint(int x1, int y1, int x2, int y2, int x, int y)
  2. distance_to_endpoint(int x1, int y1, int x2, int y2, int x, int y)
  3. distance_to_line(double x1, double y1, double x2, double y2, double x3, double y3)
  4. distanceAbs(final int a, final int b)
  5. distanceBase(double[] coord1, double[] coord2, int order)
  6. distanceBetween(double lon, double lat, double otherLon, double otherLat)
  7. distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude)
  8. distanceBetween(double x1, double y1, double x2, double y2)
  9. distanceBetween(double x1, double y1, double x2, double y2)