我正在尝试在特定数量的英里范围内查询更大的城市半径。例如,该查询基于搜索距离波兰Siemianowice Slaskie 500英里范围内的用户的用户。
城市表结构
city_id_PK int(11)
region_id varchar(2)
city_name varchar(100)
latitude float(10,6)
longitude float(10,6)
mysqli查询
SELECT DISTINCT
3959 * 2 * ASIN(
SQRT(
POWER(
SIN(
(50.299999 - abs(b.latitude)) * pi() / 180 / 2
),
2
)
+
COS(50.299999 * pi()/180)
* COS(abs(b.latitude) * pi() / 180)
* POWER(
SIN(
(19.033333 - b.longitude) * pi() / 180 / 2
),
2
)
)
) AS distance
FROM
users a,
city b
WHERE
a.user_name != 'myusername'
AND b.city_name = 'siemianowice slaskie'
AND a.region_id = b.region_id
HAVING
distance <= 500
ORDER BY
distance,
RAND()
距离总是太小。
结果
+-----------------------+
| distance |
+-----------------------+
|0.000018115605488822287|
|0.000018115605488822287|
|0.000018115605488822287|
|... |
|.... |