经纬度最近的位置 [英] Nearest locations with latitude and longitude
本文介绍了经纬度最近的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是有一家商店的经度和纬度,现在我想找出开车1小时或说10公里以外的所有商店.
I just have latitude and longitude of a store, now I want to find out all the stores near by in 1 hour drive or say at 10 KM distance.
我的桌子是
Id, storeName, store_lat, store_lng
说我已选择商店1的经度和纬度,我想找出附近的所有商店.如何使用php/mysql做到这一点.
Say I have selected lat and lng of store 1 and I want to find out all the nearby stores. How to do that using php/mysql.
我已经检查了很多关于SO的帖子,但是当我运行查询时,它始终会返回0个结果.
I have checked many post on SO but when I am running query, it's returning 0 results all the time.
请帮助,谢谢!
推荐答案
假设您获得了$ lat和$ long作为起始点的纬度/经度:
Assuming you get $lat and $long as latitidue/longitude of your starting point:
$sql = 'SELECT *, (6371 * acos(cos(radians(' . $lat . ')) * cos(radians(latitude)) * cos(radians(longitude) - radians(' . $lng . ')) + sin(radians(' . $lat . ')) * sin(radians(latitude)))) AS distance from table_name WHERE distance < 10';
这篇关于经纬度最近的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文