Java Distance Calculate dist(double lat1, double long1, double lat2, double long2)

Here you can find the source of dist(double lat1, double long1, double lat2, double long2)

Description

distance between two coordinates in kilometers

License

Open Source License

Declaration

public static double dist(double lat1, double long1, double lat2,
        double long2) 

Method Source Code

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

public class Main {
    /**//from   w w w.j a  va2s.c  o m
     * distance between two coordinates in kilometers
     */
    public static double dist(double lat1, double long1, double lat2,
            double long2) {
        final double d2r = Math.PI / 180.0;
        final double dlong = (long2 - long1) * d2r;
        final double dlat = (lat2 - lat1) * d2r;
        final double a = Math.pow(Math.sin(dlat / 2.0), 2.0)
                + Math.cos(lat1 * d2r) * Math.cos(lat2 * d2r)
                * Math.pow(Math.sin(dlong / 2.0), 2.0);
        final double c = 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a));
        final double d = 6367.0 * c;
        return d;
    }
}

Related

  1. computeDistanceImpl(final String firstStringInAlgorithm, final String secondStringInAlgorithm)
  2. computeDistanceInMiles(Double lat1, Double lon1, Double lat2, Double lon2)
  3. computeDistanceMap(int[][] image)
  4. computeDistanceSqr(double t, double b1, double b2, double b3, double b4, double b5, double b6)
  5. computeDistanceUsingRadians(double lat1Radians, double lng1Radians, double lat2Radians, double lng2Radians)
  6. dist(double x1, double y1, double z1, double x2, double y2, double z2)
  7. dist(final double x0, final double y0, final double x1, final double y1)
  8. dist(float x1, float y1, float x2, float y2)
  9. dist(float x1, float y1, float x2, float y2)