1. 程式人生 > >查詢附近的點sql語句

查詢附近的點sql語句

原理:

統計微信公眾號獲取位置介面,獲取到位置和經緯度,用此經緯度ajax讀取資料庫中的點的資料,更新資料。

 

//通過sql語句查詢距離5公里之內的門店
    $sql = "select * from (select shop_id,shop_name,shop_tel,shop_position,shop_logo,  ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($latitude*PI()/180-`shop_wei`*PI()/180)/2),2)+COS($latitude*PI()/180)*COS(`shop_wei`*PI()/180)*POW(SIN(($longitude*PI()/180-`shop_jing`*PI()/180)/2),2)))*1000) AS distance from sp_shop order by distance ) as a where a.distance<=5000";