此 SQL 查询中返回的“距离”单位是什么

Which unit is `distance` returning in this SQL query

我正在处理 Google 地图 API 中的一些 latitude/longitude 相关代码,它为我提供了以下 SQL 语句

SELECT id, (
  3959 * acos( cos( radians(37) ) *
  cos( radians( lat ) ) *
  cos( radians( lng ) - radians(-122) ) +
  sin( radians(37) ) * sin( radians( lat ) ) ) )
AS distance
FROM marker
HAVING distance < 25
ORDER BY distance LIMIT 0 , 20;

Link 到 Google 地图示例在这里:https://developers.google.com/maps/articles/phpsqlsearch_v3

但是返回的距离超过 7,000,而我知道我在数据库中的所有条目彼此之间的距离都在 50 英里以内。我已经使用 http://www.movable-type.co.uk/scripts/latlong.html 验证了这一点,它也通过了 Haversine 公式。

所以我很好奇我在提供的查询中做错了什么,returns:

(IMAGE) http://gyazo.com/ece247747616c5a412edd40c82c4b0ce -- (Failed to upload image, format not accepted???).

所有点数均来自

long: 39.410870
lat:  -107.102180

完整查询如下:

SELECT id,`user_long`,`user_lat`,
( 3959 * acos( cos( radians(39.410870) ) * cos( radians( `user_lat` ) ) * cos( radians( `user_long` ) - radians(-107.102180) ) + sin( radians(39.410870) ) * sin( radians( `user_lat` ) ) ) ) AS distance
FROM `accounts`
ORDER BY distance LIMIT 0 , 20

正如你在结果中看到的那样,这真的很奇怪,因为即使与自身相比,距离也 > 7000。

ID:    1
LONG: 39.410870
LAT:  -107.102180
DIST: 7923.067131806453

单位是英里。

你好像有经纬度reversed/swapped.

纬度的有效范围是-90到+90,不能是-107(度)。

如果您要指定科罗拉多州丹佛以西的位置,Grand Junction 的中途,请交换纬度和经度的值。

"great circle calculation" 看起来是正确的,它将达到 return 英里,因为您要乘以 3959。(您需要用另一个常数替换该常数以获得距离单位以外的其他距离单位英里。)

看起来您在表达式中正确放置了固定的纬度和经度...我怀疑 user_latuser_lng 中的值是 swapped/reversed。