Java Distance Calculate distance(double latA, double logA, double latB, double logB)

Here you can find the source of distance(double latA, double logA, double latB, double logB)

Description

distance

License

Open Source License

Declaration

public static double distance(double latA, double logA, double latB, double logB) 

Method Source Code

//package com.java2s;

public class Main {
    private static final double PI = 3.14159265358979324D;

    public static double distance(double latA, double logA, double latB, double logB) {
        double earthR = 6371000;
        double x = Math.cos(latA * Math.PI / 180) * Math.cos(latB * Math.PI / 180)
                * Math.cos((logA - logB) * Math.PI / 180);
        double y = Math.sin(latA * Math.PI / 180) * Math.sin(latB * Math.PI / 180);
        double s = x + y;
        if (s > 1)
            s = 1;//from   w w w.  j ava 2s . co  m
        if (s < -1)
            s = -1;
        double alpha = Math.acos(s);
        double distance = alpha * earthR;
        return distance;
    }
}

Related

  1. distance(double lat1, double lng1, double lat2, double lng2)
  2. distance(double lat1, double lon1, double lat2, double lon2)
  3. distance(double lat1, double lon1, double lat2, double lon2)
  4. distance(double lat1, double lon1, double lat2, double lon2)
  5. distance(double lat1, double lon1, double lat2, double lon2)
  6. distance(double latDegrees1, double lonDegrees1, double latDegrees2, double lonDegrees2)
  7. distance(double latitude1, double longitude1, double latitude2, double longitude2)
  8. distance(double lon1, double lat1, double lon2, double lat2)
  9. distance(double u, double v, double pu, double pv)