Java tutorial
//package com.java2s; public class Main { final static double RADIAN = 0.01745329; final static int EARTH_RADIUS = 6371000; public static double distanceTo(double fromLat, double fromLng, double toLat, double toLng) { double fromLatRad = calculateRadian(fromLat); double fromLngRad = calculateRadian(fromLng); double toLatRad = calculateRadian(toLat); double toLngRad = calculateRadian(toLng); return EARTH_RADIUS * (Math.PI / 2 - Math.asin(Math.sin(fromLatRad) * Math.sin(toLatRad) + Math.cos(fromLngRad - toLngRad) * Math.cos(toLatRad) * Math.cos(fromLatRad))); } public static double calculateRadian(double value) { return value * RADIAN; } }