Distance between two points / coordinates

Latitude and Longitude in the formula must be radians, example: Lat1 = Lat1 * PI / 180
6378.137 is diameter of earth in kilometers (WGS84 datum). Use: 3963.191 for miles.
PI = 3.14159265358979323846
Lat1 = Lat1 * PI / 180
Lon1 = Lon1 * PI / 180
Lat2 = Lat2 * PI / 180
Lon2 = Lon2 * PI / 180
D = 6378.137 * ACos( Cos( Lat1 ) * Cos( Lat2 ) * Cos( Lon2 - Lon1 ) + Sin( Lat1 ) * Sin( Lat2 ) )
If your programming language or application does not have ACos function, maybe has Atn, use the following formula instead to calculate via ArcTan mathematical function.
Provide Latitude and Longitude as decimals, no need to convert them to radians.
D = 6378.137 * Atn( Sqr( ( 1 - ( Sin( Lat1 / 57.29577951 ) * Sin( Lat2 / 57.29577951 ) + Cos( Lat1 / 57.29577951 ) * Cos( Lat2 / 57.29577951 ) * Cos( Lon2 / 57.29577951 - Lon1 / 57.29577951 ) ) ^2 ) ) / (Sin ( Lat1 / 57.29577951 ) * Sin( Lat2 / 57.29577951 ) + Cos( Lat1 / 57.29577951 ) * Cos( Lat2 / 57.29577951 ) * Cos( Lon2 / 57.29577951 - Lon1 / 57.29577951 ) ) )
Code samples:
Java
ASP
C+
C#
Perl
PHP
 Reference data
Administrative divisions
Countries
Countries names
Currencies
Languages
Postal codes format
Time zones
Formulas & samples
Distance between points
Locate points in a radius
Find postal code of a point