Distance between to points (londitude and latitude)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
icarpenter
Forum Commoner
Posts: 84
Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England

Distance between to points (londitude and latitude)

Post 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
User avatar
icarpenter
Forum Commoner
Posts: 84
Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England

Post 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
Post Reply