Java Distance Calculate calculateDistance(double lat1, double lng1, double lat2, double lng2)

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

Description

calculate Distance

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double calculateDistance(double lat1, double lng1, double lat2, double lng2) {
        double earthRadius = 6371393.0;
        double dLat = Math.toRadians(lat2 - lat1);
        double dLng = Math.toRadians(lng2 - lng1);
        double sindLat = Math.sin(dLat / 2);
        double sindLng = Math.sin(dLng / 2);
        double a = Math.pow(sindLat, 2)
                + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        double dist = earthRadius * c;

        return dist;
    }/*from ww  w  . j  a  va 2 s .c  o m*/
}

Related

  1. calcDistance(int x1, int y1, int x2, int y2)
  2. calcDistanceBetweenCoords(double startLat, double startLon, double endLat, double endLon)
  3. calcDistanceHubery(double lat1, double lng1, double lat2, double lng2, int type)
  4. calcDistanceIfAccel(double startVelocity, double accel, double targetVelocity, double duration)
  5. calcDistanceToStop(double startingVelocity, double maxDeceleration)
  6. calculateDistance(Double lng1, Double lat1, Double lng2, Double lat2)
  7. calculateDistance(Double prevLat, Double prevLon, Double currentLat, Double currentLon)
  8. calculateDistance(double rssi, double txPower)
  9. calculateDistance(final double x1, final double y1, final double x2, final double y2)