3

选择邮政编码,纬度,lng,截断((度(acos(sin(radians(lat)))* sin(弧度('.$latitude.'))+ cos(弧度(lat))* cos(弧度('.$latitude. ')) * cos( radians( lng- ('.$longitude.'))) ) ) * 69.172), 2) as distance FROMmyData
此查询计算距离(以英里为单位)。但是当我在谷歌地图上检查相同纬度和经度的距离时,我的结果不匹配。如果距离在 10 英里左右,那么我的结果有点准确,但超过了它就出错了(例如,我的结果显示 13 英里,而谷歌显示相同邮政编码值的 22 英里)

我从http://forums.mysql.com/read.php?23,3868,3868#msg-3868得到了这个查询

怎样才能准确。有任何想法吗?感谢帮助。

更新

我在 PHP 中尝试了@Blixt 代码。拿起 2 个示例邮政编码及其经纬度

//B28 9ET
$lat1 = 52.418819;
$long1 = -1.8481053;

//CV5 8BX
$lat2 = 52.4125573;
$long2 = -1.5407743;

$dtr = M_PI / 180;
$latA = $lat1 * $dtr;
$lonA = $long1 * $dtr;
$latB = $lat2 * $dtr;
$lonB = $long2 * $dtr;
$EarthRadius = 3958.76; //miles
echo $distance = $EarthRadius * acos(cos($latA) * cos($latB) * cos($lonB - $lonA) + sin($latA) * sin($latB));

结果:

我的应用程序 - 12.95 英里

谷歌 - 17.8 英里

任何想法如何让它正确?

4

1 回答 1

2

看看这个源代码。当我针对其他各种测量服务对其进行测试时,它似乎得到了相同的结果。它是 C#,但数学应该很容易转换。

以下是相关部分:

public const double EarthRadius = 6371.0072; // Kilometers
//public const double EarthRadius = 3958.76; // Miles

/* ... */

const double dtr = Math.PI / 180;
double latA = this.Latitude * dtr;
double lonA = this.Longitude * dtr;
double latB = other.Latitude * dtr;
double lonB = other.Longitude * dtr;

return GpsLocation.EarthRadius * Math.Acos(Math.Cos(latA) * Math.Cos(latB) * Math.Cos(lonB - lonA) + Math.Sin(latA) * Math.Sin(latB));

注意:地球不是完美的球形,因此使用的常数可能会有所不同。没有简单的方法可以使测量结果真正准确。参见维基百科

于 2009-06-12T11:47:50.643 回答