Here you can find the source of dist(double lat1, double long1, double lat2, double long2)
public static double dist(double lat1, double long1, double lat2, double long2)
//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; } }