确定一定范围内的经度和纬度 [英] Determine longitudes and latitudes within a range
问题描述
我在我的数据库中有位置。一个位置有属性的纬度和经度(从谷歌地图取得,例如:48.809591)。
是否有任何查询可以帮助我检索另一个位置范围内的位置?
示例:
我有纬度位置A = 48.809591和经度= 2.124009,并希望检索位于距离地点5英里内的数据库中的所有位置对象。我首先想到的是检索位置square位置location.latitude< A.latitude + 5英里和location.latitude> A.latitude - 5英里and location.longitude< A.longitude + 5 miles and location.longitude> A.longitude - 5 miles,然后从类似 http://www.movable-type.co.uk/scripts/latlong.html
有什么想法?
以防万一您使用MySQL作为DBMS 1 ,您可能有兴趣查看以下演示文稿:
1 即使你不是,这仍然是有趣和适用的。
2 还有一个 pdf版本。
I have locations in my database. A location has the attributes latitude and longitude (taken from google maps, example: 48.809591). Is there any query that could help me retrieve the locations within a range of another location?
Example: I have the location A with latitude = 48.809591, and longitude = 2.124009 and want to retrieve all location objects in my database that are within 5 miles of location A
My first thought was to retrieve the locations in a square where location.latitude < A.latitude + 5 miles and location.latitude > A.latitude - 5 miles and location.longitude < A.longitude + 5 miles and location.longitude > A.longitude - 5 miles, and then remove the irrelevant locations from the returned array with the help of something like http://www.movable-type.co.uk/scripts/latlong.html
Any ideas?
Just in case you're using MySQL as your DBMS1, you may be interested in checking out the following presentation:
The author describes how you can use the Haversine Formula in MySQL to order spatial data by proximity and limit the results to a defined radius. More importantly, he also describes how to avoid a full table scan for such queries, using traditional indexes on the latitude and longitude columns.
1 Even if you aren't, this is still interesting and applicable.
2 There is also a pdf version of the presentation.
这篇关于确定一定范围内的经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!