Mysql sql语句 按坐标查询 并按距离排序
作者:互联网
参数1 :lat
参数2:lng
参数3: lat
参数4: 城市码(可无)
参数5:限制?公里内
参数6:限制查询的数量
1 sqlStr := `SELECT 2 id,longitude,latitude,institution_name,intro,mobile,address,cover, 3 ( 4 6371 * acos ( 5 cos ( radians( ? ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( ? ) ) + sin ( radians( ? ) ) * sin( radians( latitude ) ) 6 ) 7 ) 8 AS 9 distance 10 FROM 11 nts_institution 12 WHERE 13 status=1 AND city=? 14 HAVING 15 distance < ? 16 ORDER BY 17 distance ASC 18 LIMIT ?;`
`SELECT id,longitude,latitude,institution_name,intro,mobile,address,cover, ( 6371 * acos ( cos ( radians( ? ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( ? ) ) + sin ( radians( ? ) ) * sin( radians( latitude ) ) ) ) AS distance FROM nts_institution WHERE status=1 AND city=? HAVING distance < ? ORDER BY distance ASC LIMIT ?;`View Code
标签:语句,distance,cos,Mysql,radians,institution,sql,latitude,sin 来源: https://www.cnblogs.com/arvin-an/p/14250207.html