Here you can find the source of distanceBetween(double latitude1, double longitude1, double latitude2, double longitude2)
public static double distanceBetween(double latitude1, double longitude1, double latitude2, double longitude2)
//package com.java2s; //License from project: Apache License public class Main { public static double distanceBetween(double latitude1, double longitude1, double latitude2, double longitude2) { double distance = 0.0; double deltaLat = Math.toRadians(latitude2 - latitude1); double deltaLon = Math.toRadians(longitude2 - longitude1); latitude1 = Math.toRadians(latitude1); latitude2 = Math.toRadians(latitude2); longitude1 = Math.toRadians(longitude1); longitude2 = Math.toRadians(longitude2); double earthRadius = 6371 * 1000; double a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) + Math.cos(latitude1) * Math.cos(latitude2) * Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); distance = earthRadius * c;/*from w ww .j a v a 2 s . co m*/ return distance; } }