使用纬度/经度和公里距离进行简单计算?
我可以做一个简单的计算,将 km 转换为一个值,我可以将其添加到纬度或经度浮点数以计算搜索的边界框吗? 它不需要完全准确。
例如:如果给我一个英国伦敦的纬度/经度(51.5001524,-0.1262362),我想计算从该点向东/向西 25 公里的经度是多少,以及从该点向北/向南 25 公里的经度是多少点,我需要做什么才能将 25 公里转换成小数以添加到上面的值中?
我正在寻找一般的经验法则,即:1km == +/- 0.XXX
编辑:
我最初搜索“lat lon”没有返回此结果:
接受的答案似乎足以满足我的要求。
Is there a simple calculation I can do which will convert km into a value which I can add to a lat or lon float to calculate a bounding box for searches? It doesn't need to be completely accurate.
For instance: if I were given a lat/lon for London, England (51.5001524, -0.1262362) and I wanted calculate what the lat would be 25km east/west from that point, and what the lon would be 25km north/south of that point, what would I need to do to convert the 25km into a decimal to add to the values above?
I'm looking for a general rule-of-thumb, ie: 1km == +/- 0.XXX
Edit:
My original search for "lat lon" didn't return this result:
How to calculate the bounding box for a given lat/lng location?
The accepted answer seems adequate for my requirements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
近似转换为:
这并不完全正确地反映地球极地扁平化的情况 - 为此,您可能需要使用 WGS84 的更复杂的公式参考椭球体(用于 GPS 的模型)。 但对于您的目的来说,该错误可能可以忽略不计。
来源:http://en.wikipedia.org/wiki/Latitude
警告:请注意,经纬度坐标以度数表示,而大多数(所有?)语言中的
cos
函数通常接受弧度,因此 度数需要弧度转换。The approximate conversions are:
This doesn't fully correct for the Earth's polar flattening - for that you'd probably want a more complicated formula using the WGS84 reference ellipsoid (the model used for GPS). But the error is probably negligible for your purposes.
Source: http://en.wikipedia.org/wiki/Latitude
Caution: Be aware that latlong coordinates are expressed in degrees, while the
cos
function in most (all?) languages typically accepts radians, therefore a degree to radians conversion is needed.感谢 Jim Lewis 的出色回答,我想通过我在 Swift 中的函数来说明这个解决方案:
在这个函数中为了转换距离,我使用以下公式:
Thanks Jim Lewis for his great answer and I would like to illustrate this solution by my function in Swift:
In this function to convert distance I use following formulas:
如果您使用 Java、Javascript 或 PHP,那么有一个库可以使用一些非常复杂(但仍然很快)的三角函数来精确地执行这些计算:
http://www.jstott.me.uk/jcoord/
If you're using Java, Javascript or PHP, then there's a library that will do these calculations exactly, using some amusingly complicated (but still fast) trigonometry:
http://www.jstott.me.uk/jcoord/
http://www.jstott.me.uk/jcoord/ - 使用此库
http://www.jstott.me.uk/jcoord/ - use this library
有趣的是我没有看到提及 UTM 坐标。
https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system。
至少如果你想将公里添加到同一区域,它应该很简单(在Python中: https:// pypi.org/project/utm/ )
utm.from_latlon 和 utm.to_latlon。
Interesting that I didn't see a mention of UTM coordinates.
https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system.
At least if you want to add km to the same zone, it should be straightforward (in Python : https://pypi.org/project/utm/ )
utm.from_latlon and utm.to_latlon.
这个更准确(Haversin公式)我们使用地球半径
This is more accurate (Haversin formula) we use the radius of the earth
为什么不使用正确制定的地理空间查询???
以下是 STContains 地理空间函数的 SQL Server 参考页:
https://learn.microsoft.com/en-us/sql/t-sql/spatial-geography/stcontains-geography-data-type?view=sql -server-ver15
或者如果您不想使用盒子和弧度转换,您可以始终使用距离函数来查找您需要的点:
几乎所有数据库都应该有类似的功能。
如果您正确实施了地理空间索引,您的搜索将比您正在使用的方法快得多
Why not use properly formulated geospatial queries???
Here is the SQL server reference page on the STContains geospatial function:
https://learn.microsoft.com/en-us/sql/t-sql/spatial-geography/stcontains-geography-data-type?view=sql-server-ver15
or if you do not waant to use box and radian conversion , you cna always use the distance function to find the points that you need:
There should be similar functionality for almost any database out there.
If you have implemented geospatial indexing correctly your searches would be way faster than the approach you are using