判断我是否在附近
我已经得到了我当前的位置,并且我已经得到了地点列表。
我想做的是弄清楚我是否在其中一个地方附近,附近大约是+100m。 我不想显示地图,只想知道我是否在附近。
哪些类型的 php 库可用于比较位置/经纬度? 或者我可以用数学来解决这个问题吗?
谢谢
I've got my current location lat long and I've got a list of places and there lat long.
What I'd like to do is figure out if I'm nearby one of the places, nearby would be something like +100m. I don't want to display a map, just know if I'm near it.
What kind of php libraries are available for comparing location/lat long? Or can I solve it with math?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用经度和纬度确定距离
至少,如果身高对你来说不重要的话。
如果您需要取决于道路或步行能力的高度和/或距离(这甚至是一个词吗?),我认为谷歌地图会更准确。
Using Longitude and Latitude to Determine Distance
at least, if height isn't important to you.
if you need the height and/or distance dependend on roads or walkability (is this even a word?), i think google maps would be more exact.
给定球面坐标(纬度/经度),计算两点之间的距离并不难。 在谷歌上快速搜索“纬度经度距离”就会发现这个方程。
显然是这样的:
其中
a
和b
是您的点,r
是地球的平均半径(6371 公里)。一旦您能够计算给定坐标的两点之间的距离,您将需要循环遍历所有地标并查看您当前的位置是否靠近一个。
但是,如果您有很多地标,您可能需要使用空间搜索算法(可能使用 Quadtree 或类似的数据结构)。
It's not hard to calculate distance between two points, given their spherical coordinates (latitude/longitude). A quick search for "latitude longitude distance" on Google reveals the equation.
Apparently it's something like this:
where
a
andb
are your points andr
is the earth's mean radius (6371 km).Once you're able to calculate the distance between two points given their coordinates, you'll want to loop through all the landmarks and see if your current location is near one.
However, if you have many landmarks, you might want to use a spatial search algorithm (maybe using a Quadtree or a similar data structure).
http://blog.wekeroad.com/2007/08/30/ LINQ 示例的 linq-and-geocoding
http://www.codeproject.com/KB/cs/distance Betweenlocations.aspx 对于 C# 和 TSQL 示例
http://blog.wekeroad.com/2007/08/30/linq-and-geocoding for LINQ Example
http://www.codeproject.com/KB/cs/distancebetweenlocations.aspx for C# and TSQL Example
我不熟悉解决这个问题的软件库。 但如果你在 2D 空间中谈论,那么我想到了一些数学:
你可以使用以下计算找到 2D 空间中任意 2 个点的距离:
distance = sqrt( (X2 - X1)^2 + ( Y2 - Y1 )^2 )
其中 ^2 表示由 2 提供动力。
所以假设您有一个 Point 对象数组(这里我为 Points 定义了一个简单的类),这样您就可以找出哪些点是相邻的:
编辑:抱歉,我忘记了直线距离公式。 X 轴和 Y 轴距离值均应乘以 2,然后将其总和开平方即可得到结果。 该代码现已更正。
I'm not familiar with software libraries for this problem. but if you are talking in 2D space, then here is some math that comes to my mind:
you can find the distance of any 2 points in the 2D space using this calculation:
distance = sqrt( (X2 - X1)^2 + (Y2 - Y1 )^2 )
inwhich ^2 means powered by 2.
so le'ts say you have an array of Point objects (here I define a simple class for Points), this way you can find out which points are neighbored:
edit: I'm sorry, I had forgotten the linear distance formula. both X and Y axis distance values should be powered by 2 and then the sqrt of their sum is the result. the code is now corrected.
我对这个包不熟悉,但是
GeoClass 可能有用。
我在 FreeGIS 网站上找到了它。 如果这不是您想要的,软件部分列出了许多其他 php 软件包。
I'm not familiar with the package, but
GeoClass may be useful.
I found it on the FreeGIS website. If that isn't quite what you were looking for, there were many other php packages listed in the software section.