Javascript GPS坐标:一个点周围1平方公里
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4000886/
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
GPS coordinates: 1km square around a point
提问by Eamorr
I was hoping someone out there could provide me with an equation to calculate a 1km square (X from a.aaa to b.bbb, Y from c.ccc to c.ccc) around a given point, say lat = 53.38292839
and lon = -6.1843984
? I'll also need 2km, 5km and 10km squares around a point.
我希望有人可以为我提供一个方程式来计算给定点周围的 1 平方公里(X 从 a.aaa 到 b.bbb,Y 从 c.ccc 到 c.ccc),比如说lat = 53.38292839
和lon = -6.1843984
?我还需要一个点周围 2km、5km 和 10km 的正方形。
I've tried googling around to no avail... It's late at night and was hoping someone might have quick fix handy before I delve into the trigonometry...
我试过谷歌搜索无济于事......现在已经深夜了,希望有人在我深入研究三角学之前可以快速修复......
I'll be running all this in Javascript, although any language is fine.
我将在 Javascript 中运行所有这些,尽管任何语言都可以。
回答by Tommy
If the world were a perfect sphere, according to basic trigonometry...
如果世界是一个完美的球体,根据基本的三角学......
Degrees of latitude have the same linear distance anywhere in the world, because all lines of latitude are the same size. So 1 degree of latitude is equal to 1/360th of the circumference of the Earth, which is 1/360th of 40,075 km.
纬度在世界任何地方都具有相同的线性距离,因为所有纬度线的大小都相同。所以1度纬度等于地球周长的1/360,即40,075公里的1/360。
The length of a lines of longitude depends on the latitude. The line of longitude at latitude l will be cos(l)*40,075 km. One degree of longitude will be 1/360th of that.
经线的长度取决于纬度。纬度 l 处的经线将为 cos(l)*40,075 km。一度经度将是其 1/360。
So you can work backwards from that. Assuming you want something very close to one square kilometre, you'll want 1 * (360/40075) = 0.008983 degrees of latitude.
所以你可以从那个开始倒退。假设您想要非常接近一平方公里的区域,您将需要 1 * (360/40075) = 0.008983 度的纬度。
At your example latitude of 53.38292839, the line of longitude will be cos(53.38292839)*40075 = [approx] 23903.297 km long. So 1 km is 1 * (360/23903.297) = 0.015060 degrees.
在您的示例纬度 53.38292839 处,经度线将为 cos(53.38292839)*40075 = [大约] 23903.297 公里长。所以 1 公里是 1 * (360/23903.297) = 0.015060 度。
In reality the Earth isn't a perfect sphere, it's fatter at the equator. And the above gives a really good answer for most of the useful area of the world, but is prone to go a little odd near the poles (where rectangles in long/lat stop looking anything like rectangles on the globe). If you were on the equator, for example, the hypothetical line of longitude is 0 km long. So how you'd deal with a need to count degrees on that will depend on why you want the numbers.
实际上,地球不是一个完美的球体,它在赤道处更胖。以上为世界上大多数有用的区域提供了一个非常好的答案,但在极点附近容易变得有点奇怪(长/纬度中的矩形看起来不像地球上的矩形)。例如,如果您在赤道上,则假设的经线长度为 0 公里。因此,您如何处理需要计算度数的需求将取决于您想要这些数字的原因。
回答by Jim
Here is something from my notes to be used on Android with its decimal GPS.
这是我的笔记中的一些内容,可在带有十进制 GPS 的 Android 上使用。
Lat Long: NY City 40N 47 73W 58 40.783333 73.966667
经纬度:纽约市 40N 47 73W 58 40.783333 73.966667
Wash DC 38N 53 77W 02 38.883333 77.033333
洗 DC 38N 53 77W 02 38.883333 77.033333
yields = 209 miles !! VERY CLOSE
产量 = 209 英里!!很接近
Distance (miles) (x) = 69.1 (lat2-lat1) Distance(miles) (y) = 53.0 (long2 - long1) As crow flys sqrt (x2 + y2) ... duh!@
距离(英里)(x) = 69.1 (lat2-lat1) 距离(miles) (y) = 53.0 (long2 - long1) As crow fly sqrt (x2 + y2) ... duh!@
delta(LAT) / Mile = .014472 delta(LONG) / Mile = .018519
delta(LAT) / 英里 = .014472 delta(LONG) / 英里 = .018519
Using a box as approximation To find someone within 100 miles (100 north / 100 south, 100 E / 100 W) From 0,0 -14.472 / + 14.472 , -18.519 / 18.519
使用方框作为近似值 在 100 英里(北 100 / 南 100,东经 100 西 / 100 西)内找到某人 0,0 -14.472 / + 14.472 ,-18.519 / 18.519
回答by Evan O' Keeffe
A simpler way of generating a gps square given the centre would be to use the indirect Vincenty algorithm.The Javascript code here shows how to do it http://www.movable-type.co.uk/scripts/latlong.html. Creating a square using a circle isn't to hard. Squares are equal distance to each point. So given a centre point, distance from the centre, change the bearing from 0 or any number depending on rotation of the square and increment by 90 degrees or PI/2 radians. By incrementing by 90 degrees each time and you will up with a square in circular space.
给定中心生成 gps 方块的一种更简单的方法是使用间接 Vincenty 算法。此处的 Javascript 代码显示了如何做到这一点http://www.movable-type.co.uk/scripts/latlong.html。使用圆形创建正方形并不难。正方形到每个点的距离相等。因此,给定一个中心点,距中心的距离,根据正方形的旋转从 0 或任何数字更改方位角,并增加 90 度或 PI/2 弧度。通过每次增加 90 度,您将在圆形空间中得到一个正方形。
I use this myself for generating GPS points around a centre point with a given distance .---. --/- --0-- -/-- .---.
我自己使用它在给定距离的中心点周围生成 GPS 点.---。--/- --0-- -/-- .---。
回答by Abel Callejo
TL;DR
TL; 博士
10 km
= 0.08999
radius from a certain geopoint
. This calculation is only based on latitude values and applies only to geopoints with WGS84 projection.
10 km
=0.08999
从某个半径开始geopoint
。此计算仅基于纬度值并且仅适用于具有 WGS84 投影的地理点。
More details
更多细节
If you want a more accurate answer you must have to calculate it by building a function of some sort. However it still don't guarantee because people even quarrel for the degrees of error. Taking altitude into account, mercator or not, etc.
如果你想要一个更准确的答案,你必须通过构建某种函数来计算它。然而它仍然不能保证,因为人们甚至为错误的程度而争吵。考虑到海拔高度,墨卡托与否等。
Caution
警告
The value above is just a rule of a thumbso don not use it for critical applications.
上面的值只是一个经验法则,所以不要将它用于关键应用程序。
Reference
参考
GIS StackExchange, How do I calculate the bounding box for given a distance and latitude/longitude, answer by David the Australian developer
GIS StackExchange,如何计算给定距离和纬度/经度的边界框,澳大利亚开发人员大卫回答