Fastest Way to Find Distance Between Two Lat/Long Points

后端 未结 15 1296
时光说笑
时光说笑 2020-11-21 10:12

I currently have just under a million locations in a mysql database all with longitude and latitude information.

I am trying to find the distance between one point a

15条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-21 10:27

    SELECT * FROM (SELECT *,(((acos(sin((43.6980168*pi()/180)) * 
    sin((latitude*pi()/180))+cos((43.6980168*pi()/180)) * 
    cos((latitude*pi()/180)) * cos(((7.266903899999988- longitude)* 
    pi()/180))))*180/pi())*60*1.1515 ) as distance 
    FROM wp_users WHERE 1 GROUP BY ID limit 0,10) as X 
    ORDER BY ID DESC
    

    This is the distance calculation query between to points in MySQL, I have used it in a long database, it it working perfect! Note: do the changes (database name, table name, column etc) as per your requirements.

提交回复
热议问题