所以我有这个PHP代码:
$lat1 = 39.210637;
$lng1 = -105.534551;
$lat2 = 39.725865;
$lng2 = -105.016820;
$theta = $lng1 - $lng2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$kilometers = $miles * 1.60934;
$meters = $kilometers * 1000;
返回:72503米
我尝试在MySQL中编写完全相同的代码:
ROUND((RADIANS(ACOS(SIN(RADIANS(39.210637)) * SIN(RADIANS(39.725865)) + COS(RADIANS(39.210637)) * COS(RADIANS(39.725865)) * COS(RADIANS(-105.534551 - (-105.016820)))))) * 60 * 1.1515 * 1.60934 * 1000)
返回:22米
为什么他们应该是相同的功能呢?我做错了吗?
谢谢!
答案 0 :(得分:1)
糟糕,看起来我错过了一个应该是MySQL中的DEGREES()的rad2deg,所以代码应该是:
ROUND((DEGREES(ACOS(SIN(RADIANS(39.210637)) * SIN(RADIANS(39.725865)) + COS(RADIANS(39.210637)) * COS(RADIANS(39.725865)) * COS(RADIANS(-105.534551 + 105.016820))))) * 60 * 1.1515 * 1.60934 * 1000)
现在它运作正常。