ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 使用MySQL计算一个坐标点和数据库中门店的距离,并按距离排序 参考文档:[https://www.cnblogs.com/hanshuai0921/p/6992447.html](https://www.cnblogs.com/hanshuai0921/p/6992447.html) ### 公式一 ``` SELECT *, ROUND((ACOS(SIN((22.574136 * PI()) / 180 ) *SIN((latitude * PI()) / 180 ) +COS((22.574136 * PI()) / 180 ) * COS((latitude * PI()) / 180 ) *COS((114.134837 * PI()) / 180 - (longitude * PI()) / 180 ) ) * 6380 * 1000)) AS distance FROM shops WHERE latitude > 22.574136-1 AND latitude < 22.574136+1 AND longitude > 114.134837-1 AND longitude < 114.134837+1 ORDER BY distance ASC LIMIT 10 ``` ### 公式二 ``` SELECT *, ROUND((6380 * 2 * 1000 * ASIN(SQRT(POW(SIN((22.574136 * PI() / 180 - latitude * PI() / 180) / 2),2) + COS(22.574136 * PI() / 180) * COS(latitude * PI() / 180) * POW(SIN((114.134837 * PI() / 180 - longitude * PI() / 180) / 2),2))))) AS distance FROM shops WHERE latitude > 22.574136-1 AND latitude < 22.574136+1 AND longitude > 114.134837-1 AND longitude < 114.134837+1 ORDER BY distance ASC LIMIT 10 ```