php 通过谷歌地图(使用PHP)获取我当前位置半径10公里范围内的所有位置的纬度和经度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12949476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:32:15  来源:igfitidea点击:

Get Latitude and Longitude of all location that are within 10km radius of my current location through google map(using PHP)

phpgoogle-mapsgoogle-maps-api-3

提问by Ahsan aslam

i am new to Google map things. i have a table in which there are list of all the location( the location of super stores) with their Latitude and Longitude .

我是谷歌地图的新手。我有一个表格,其中列出了所有位置(超级商店的位置)及其纬度和经度。

Now i want to know all possible location(may b Latitude and Longitude ) of these super stores that are within 10km radius of my current location.

现在我想知道这些超级商店在我当前位置 10 公里半径范围内的所有可能位置(可能是纬度和经度)。

I have no idea how i can do this using Google map (in php code). What Google map API should i used ? Any suggestion ,project code, information will be helpful for me

我不知道如何使用 Google 地图(在 php 代码中)执行此操作。我应该使用什么 Google 地图 API?任何建议,项目代码,信息都会对我有帮助

Thanks in Advance

提前致谢

回答by Santosh Yadav

You can Use Following Query of Mysql to get all stores within specified miles

您可以使用Mysql的以下查询来获取指定英里内的所有商店

select * from stores where lat!='' and lng!='' and ( 3959 * acos( cos( radians(" . $centerpoints['lat'] . ") ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(" . $centerpoints['lng'] . ") ) + sin( radians(" . $centerpoints['lat'] . ") ) * sin( radians( lat ) ) ) ) < " . $distanceInMile

回答by xelber

https://developers.google.com/maps/articles/phpsqlsearch_v3Have a look at above. Should give you a good idea.

https://developers.google.com/maps/articles/phpsqlsearch_v3看看上面。应该给你一个好主意。

To find locations in your markers table that are within a certain radius distance of a given latitude/longitude, you can use a SELECT statement based on the Haversine formula. The Haversine formula is used generally for computing great-circle distances between two pairs of coordinates on a sphere. An in-depth mathemetical explanation is given by Wikipedia and a good discussion of the formula as it relates to programming is on Movable Type's site.

Here's the SQL statement that will find the closest 20 locations that are within a radius of 25 miles to the 37, -122 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude, and then asks for only rows where the distance value is less than 25, orders the whole query by distance, and limits it to 20 results. To search by kilometers instead of miles, replace 3959 with 6371.

要在给定纬度/经度的特定半径距离内查找标记表中的位置,您可以使用基于 Haversine 公式的 SELECT 语句。Haversine 公式通常用于计算球体上两对坐标之间的大圆距离。维基百科给出了深入的数学解释,并且在 Movable Type 的站点上对与编程相关的公式进行了很好的讨论。

这是将查找距离 37, -122 坐标 25 英里半径内最近的 20 个位置的 SQL 语句。它根据该行的纬度/经度和目标纬度/经度计算距离,然后仅询问距离值小于25的行,按距离对整个查询进行排序,并将其限制为20个结果。要按公里而不是英里搜索,请将 3959 替换为 6371。