随机lat lng坐标在另一个lat lng的x km内

时间:2015-11-02 03:55:47

标签: geometry geo

我们有一个由lat& amp; LNG

我们想要生成一些其他随机lat&距离这个位置20公里的位置

有没有人有这个

的好公式

1 个答案:

答案 0 :(得分:1)

在范围r中生成两个统一的随机值Fi0..1 将距离计算为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
相关问题