【发布时间】:2016-02-01 22:00:29
【问题描述】:
我们有一个由 lat & lng 指定的位置
我们想在这个位置 20 公里范围内生成一些其他随机纬度和经度位置
有没有人有一个很好的公式来解决这个问题
【问题讨论】:
我们有一个由 lat & lng 指定的位置
我们想在这个位置 20 公里范围内生成一些其他随机纬度和经度位置
有没有人有一个很好的公式来解决这个问题
【问题讨论】:
在0..1范围内生成两个均匀随机值r和Fi
计算距离为d = Radius * Sqrt(r) (description here for plane circle)
计算方位为Theta=2 * Pi * Fi
查找给定中心点的纬度/经度坐标,并在 Destination point given distance and bearing from start point 部分中将 d 和 Theta 计算为 described here
JavaScript:
(all angles
in radians)
var φ2 = Math.asin( Math.sin(φ1)*Math.cos(d/R) +
Math.cos(φ1)*Math.sin(d/R)*Math.cos(θ) );
var λ2 = λ1 + Math.atan2(Math.sin(θ)*Math.sin(d/R)*Math.cos(φ1),
Math.cos(d/R)-Math.sin(φ1)*Math.sin(φ2));
where φ is latitude, λ is longitude,
θ is the bearing (clockwise from north), d being the distance travelled,
R the earth’s radius
【讨论】: