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

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)
習慣沉默

If your database is MySQL 5.7, you can use the spatial function: ST_Distance_Sphere() to calculate the shortest distance (unit: meters) between two points on the earth.
As follows:

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

MySQL version 5.6 can use ST_Distance() to calculate distance. It should be noted that it calculates the straight-line distance between two 2-dimensional coordinate points, and the result needs to be multiplied by 111195 (radius of the earth 6371000*PI/180) to convert the value into meters.

    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!