谷歌地图 - 附近的位置
在我的网站上,会员在 Google 地图 API 上标记照片位置。经度和纬度保存在数据库(SQL)中。
有谁知道如何查找标记照片半径 100 公里内的标记照片?
假设纬度和经度是 46.03765154061627 | 14.5404052734375。是否有任何类型的数学公式可以检查 100 公里半径位置或任何其他方式?
谢谢你!
On my website members are tagging photo position on Google maps API. Longitude and latitude are saved in database (SQL).
Does anyone know how to find tagged photos that are in radius 100km of tagged photo?
Let say that latitude and longitude are 46.03765154061627 | 14.5404052734375. Is there any kind of math formula that would check 100km radius position or any other way?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以计算两点之间的大圆距离。幸运的是,使用 haversine 公式(假设地球是球形的),这相对容易。您可能需要进一步阅读并查看 JavaScript 实现 计算距离、方位和更多纬度/经度点之间的信息,作者:Chris Veness。
如果您只有少量照片,您可以简单地计算从用户提交的点到每个照片点的大圆距离。然后简单地按距离对结果列表进行排序,并仅过滤距离低于 100 公里阈值的照片。
但是,如果您有很多照片,您可能应该考虑从数据库中过滤这些照片。您可以使用具有地理空间索引功能的数据库。例如MySQL,PostgreSQL 和 SQL Server 2008 都具有地理空间功能(本机或通过扩展),其中包括空间索引和半正弦公式的实现。
You could calculate the great-circle distance between two points. Luckily this is relatively easy with the haversine formula, assuming a spherical representation of the earth. You may want to read further and check out the JavaScript implementation at Calculate distance, bearing and more between Latitude/Longitude points by Chris Veness.
If you will only have a handful of photos, you can simply calculate the great-circle distance from the user submitted point to each photo point. Then simply sort the result list by the distance, and filter only the photos with a distance below the 100km threshold.
However, if you will be having many photos, you should probably consider filtering these from the database. You could use a database with geo-spatial indexing capabilities. For example MySQL, PostgreSQL and SQL Server 2008 all have geo-spatial features (either natively or via extensions), which include spatial indexing and implementations of the haversine formula.
Google Maps API 包含处理纬度和经度坐标的方法。如果您要处理少量坐标,则可以轻松使用其 GLatLng 类并调用 distanceFrom 方法。
您还可以使用 GLatLngBounds,旨在查看某些坐标是否在定义的矩形边界内。
Google Maps API includes methods for handling Latitude and Longitude coordinates. If you're dealing with a small number of coordinates it would be easy to use its GLatLng class and call the distanceFrom method.
You can also use the GLatLngBounds, which is designed to see if certain coordinates are within a defined rectangular boundary.
定义一个半径为 100 公里的圆可能有点复杂(大圆计算、两点之间的距离等)...用你的点(M)定义一个 100 公里(或 200 公里)长度的“正方形”会更容易中间:
不太科学,假设
我们可以说你想要搜索图像坐标(P)满足标准的区域中的图像
(全部以度为单位)。我认为 - 对于 WEB 服务 - 这已经足够准确并且非常容易实现。
to define a circle of 100km radius may be a bit complex (great circle calculation, distance between two points, etc.) ... it's easier to define a "square shape" of 100km (or 200km) length with your point (M) in the middle:
without being too scientific, asuming
we can say that you want to search for pictures in an area where its picture coords (P) meet the criteria
(all in degrees). I would think that - for a WEB service - this is accurate enough and very easy to implement.