Reputation: 125
I am using PHPmyadmin for mysql.
I want to find the distance between 2 latitude and longitude from a table.
I am using the following query to find the distance.
But it returns in miles . How can get the distance in kilometer
Select @dist:=((ACOS(SIN(1.3903496 * PI() / 180) * SIN(latitude * PI() / 180) + COS(1.3903496 * PI() / 180) * COS(latitude * PI() / 180) * COS((103.8846613- longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance from tabl_name
Upvotes: 1
Views: 938
Reputation: 660
You can try the following SQL :
SELECT (((acos(sin((".$latitude."*pi()/180)) * sin((`Latitude`*pi()/180))+cos((".$latitude."*pi()/180)) * cos((`Latitude`*pi()/180)) * cos(((".$longitude."- `Longitude`)*pi()/180))))*180/pi())*60*1.1515*1.609344) as distance
FROM `MyTable`
Upvotes: 3
Reputation: 2256
You can directly convert the result of the query to kilometres in the query itself.
Select @dist:=((ACOS(SIN(1.3903496 * PI() / 180) * SIN(latitude * PI() / 180) + COS(1.3903496 * PI() / 180) * COS(latitude * PI() / 180) * COS((103.8846613- longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515)*1.609344 AS distance from tabl_name
Upvotes: 0