Here you can find the source of distance(double x1, double y1, double x2, double y2)
public static double distance(double x1, double y1, double x2, double y2)
//package com.java2s; //License from project: Apache License public class Main { public static double distance(double x1, double y1, double x2, double y2) { double lat1 = Math.PI / 180.0 * x1; double lat2 = Math.PI / 180.0 * x2; double dLng = Math.PI / 180.0 * (y2 - y1); double R = 3958.760; return Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(dLng)) * R; }//ww w . ja v a2 s.c o m }