计算纬度/经度坐标与另一对纬度/经度坐标之间的特定距离
我的应用程序需要能够获取用户的起始位置,然后计算该点(在所有方向上)与纬度/经度的特定距离.有人知道我该怎么做吗?
My app needs to be able to get the user starting location and then calculate lat/long coords specific distances away from that spot (in all directions). Does anyone know how I might accomplish this?
距中心点固定距离的点集具有无限个成员,因此不可能列出每个点.但是,给定一个点,您可以使用distanceFromLocation:
方法检查它是否在集合内.
The set of points a fixed distance from a central point has infinite members, so it's not possible to list out every one. However, given a single point you could check if it is within the set by using the distanceFromLocation:
method.
在数学上,给定半径坐标(长,纬度)并假设地球是平坦的,则半径(距离)为r的圆的等式为
Mathematically, given a radius coordinate (long, lat) and assuming the Earth is flat, the equation of the circle with radius (distance) r would be
r ^ 2 =(x-long)^ 2 +(y-lat)^ 2
r^2 = (x - long)^2 + (y - lat)^2
通过使用一些魔术,这变成了
With the use of some magic, this becomes
x = rcosθ-长; y = rsinθ-lat
x = r cosθ - long; y = r sinθ - lat
因此,您现在可以按任意角度打孔,并且以已知的距离/半径在圆的边缘上获得一个点.用地图术语来说,角度0将为您提供圆心,该圆心位于中心正东.正角围绕中心逆时针旋转.
So now you can punch in any arbitrary angle and for a known distance/radius get a point on the edge of the circle. In map terms, the angle 0 will give you the point on the circle straight east of the center. Positive angles go counterclockwise around the center.
在代码中:
-(CLLocation*)locationForAngle:(float)angle fromCenterLocation:(CLLocation *)center withDistance:(float)distance {
//angle must be in radians
float longitude = distance * cosf(angle) - center.coordinate.longitude;
float latitude = distance * sinf(angle) - center.coordinate.latitude;
return [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
}
我不小心删除了几个词