javascript - Baidu coordinates, returns the coordinates near the target
伊谢尔伦
伊谢尔伦 2017-05-25 15:08:24
0
1
712

Now there is a table recording user coordinates (using Baidu API), with two field records, such as coordinates (116.307852, 40.057031).

Now what should we do to find all the users within 1km of the user?

I thought I could do it directly:

select * 
from table
where x between 116.307852-1km and 116.307852+1km
and y between 40.057031-1km and 40.057031+1km

I’m not familiar with the coordinate API, thank you for helping me take a look.

Baidu map to find the distance between two points

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
習慣沉默

如果你的数据库是MySQL 5.7的话可以使用空间函数:ST_Distance_Sphere()来计算地球上两点之间的最短距离(单位:米)。
如下:

SELECT ST_Distance_Sphere(POINT(lat,lng), POINT(116.307852,40.057031)) as distance
FROM table 
where distance < 1000

MySQL 5.6版本可以使用 ST_Distance()来计算距离。需要注意的是,它计算的是两个2维坐标点之间的直线距离,结果需要乘111195(地球半径6371000*PI/180)将值转换为米。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!