我在mysql call branch中有一个表
===============================
Branch_id latitude longitude
===============================
1 3.109421 101.622913
2 3.101121 101.644913
当我输入当前位置纬度/经度时,如何从该表中选择公里计算?
例子:
如果我通过我的当前位置=3.122221 101.343913
============================================
Branch_id latitude longitude distance(km)
============================================
1 3.109421 101.622913 0.4
2 3.101121 101.644913 0.6
已编辑(已解决):
SELECT p.title,p.subtitle,p.desc,p.image,p.promotion_id,p.merchant_id,p.date_from,p.date_to,m.merchant_name,p.view,mb.latitude,mb.longitude,
(6371 * acos (cos( radians(3.158704)) * cos( radians(mb.latitude))
* cos( radians(mb.longitude) - radians(101.713963)) + sin(radians(3.158704))
* sin( radians(mb.latitude)))) AS distance
FROM merchant_branch as mb
left join merchant m on mb.merchant_id = m.merchant_id
left join promotion p on p.merchant_id = m.merchant_id
where p.promotion_id is not null order by distance asc
1条答案
按热度按时间b5lpy0ml1#
发件人:https://developers.google.com/maps/solutions/store-locator/clothing-store-locator
下面是sql语句,它在距离-33151坐标25英里的半径范围内查找最近的20个位置。它基于该行的纬度/经度和目标纬度/经度计算距离,然后仅请求距离值小于25的行,按距离排序整个查询,并将其限制为20个结果。要按公里而不是英里搜索,请将3959替换为6371。