Page 1 of 1

Distance between to points (londitude and latitude)

Posted: Thu Jul 28, 2005 12:01 pm
by icarpenter
Hi can anyone help?

I am trying to find a query that can work out the distance in miles and Km between two points using longitude and latitude using MySQL 4.1.10a...

I have the data but not a very mathamatical mind.

Any help would be greatly appreciated!

Rgds Ian

Posted: Mon Aug 01, 2005 11:30 am
by icarpenter
I found the soloution by using the following...

$lat1 = 'latitude value 1';
$lon1 = 'longitude value 1';
$earths_radius = '3956';


SELECT lat, lon,
acos(sin($lat1*3.14/180.0)*sin(lat*3.14/180.0)+
cos($lat1*3.14/180.0)*cos(lat*3.14/180.0)*
cos((lon*3.14/180.0)-($lon1*3.14/180.0)))*($earths_radius) as distance
FROM table