Querying for things near a geolocation?

£可爱£侵袭症+ 提交于 2019-12-02 18:37:42
daroczig

I think you reversed the latitude (37.780182) and longitude (-122.517349) of your central point, try:

select
    id,
    hike_title,
    lat,
    lng,
    ( 3959 * acos(  cos( radians(37) )
                  * cos( radians( lat ) )
                  * cos( radians( lng ) - radians(-122.517349) )
                  + sin( radians(37.780182) ) * sin( radians( lat ) )
                 )
    ) AS distance
FROM
    my_awesome_table
HAVING
    distance < 10000
ORDER BY
    distance
LIMIT
    0 , 50
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!