2012-10-02 2 views
0

거리 (직선)하버 사인 거리 MySQL과 PHP가 동일한 수식

에서 서로 다른 결과가 반환) (위도 48.84647 (긴) 2.41026

일부 : 13096.16 미터

PHP 공식을 사용하면 적절한 결과를 얻습니다. 내가 직접 MySQL의 쿼리로 같은 PHP 공식을 번역 할 때

하지만 - 나는 얻을 5904.2757 등이 여기에

코드입니다 :

PHP :

 
$distance = atan2(sqrt(pow(sin((($to_lat - $from_lat) * M_PI/180)/2), 2) + 
     cos(($from_lat * M_PI/180)) * cos(($to_lat * M_PI/180)) * 
     pow(sin((($to_long - $from_long) * M_PI/180)/2), 2)), sqrt(1 - (pow(sin((($to_lat - $from_lat) * M_PI/180)/2), 2) + 
     cos(($from_lat * M_PI/180)) * cos(($to_lat * M_PI/180)) * 
     pow(sin((($to_long - $from_long) * M_PI/180)/2), 2)))) * 2 * $radiusOfEarth; 

MySQL의 :

 
atan2(sqrt(pow(sin(((ap.Latitude - $from_lat) * pi()/180)/2), 2) + 
      cos(($from_lat * pi()/180)) * cos((ap.Latitude * pi()/180)) * 
      pow(sin(((ap.Longitude - $from_long) * pi()/180)/2), 2)), sqrt(1 - (pow(sin(((ap.Latitude - $from_lat) * pi()/180)/2), 2) + 
      cos(($from_lat * pi()/180)) * cos((ap.Latitude * pi()/180)) * 
      pow(sin(((ap.Longitude - $from_long) * pi()/180)/2), 2)))) * 2 * 6371000 as Distance 

답변

1

정확한 것을 원합니다.

SELECT ((ACOS(SIN(48.73233 * PI()/180) * SIN(48.84647 * PI()/180) + COS(48.73233 * PI()/180) * 
COS(48.84647 * PI()/180) * COS((2.36618 - 2.41026) * PI()/180)) * 180/PI()) * 60 *1.1515 * 1.609344 *1000) 
AS distance FROM dual; 
+0

자세한 내용은 다음을 참조하십시오. http://stackoverflow.com/questions/1006654/fastest-distance-lookup-given-latitude-longitude – av1987

+1

여전히 나에게 동일한 결과를 제공합니다. 5904.27 – Jeffz

+1

불량, 수식에 km 시간을 잊어 버렸습니다. 최종 결과에'* 1.609344'를 곱하면 KM에 1000을 곱하면 원하는 정확한 미터를 얻을 수 있습니다. – av1987