将 CLLocation 移动 x 米 [英] Moving a CLLocation by x meters

查看:21
本文介绍了将 CLLocation 移动 x 米的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了一个 CLLocation,我想将该点向东移动 x 米,向南移动 y 米.我怎样才能做到这一点?

I have a CLLocation defined, and I'd like to move that point x meters to the east and y meters to the south. How may I achieve that?

推荐答案

有一个 C 函数与您所要求的很接近,但它需要一个方位和距离.它位于 github 上的 UtilitiesGeo 类中.您可以将 CLLocation 的纬度和经度传递给它,然后根据它返回的结果 lat2 和 lon2 创建一个新的 CLLocation:

There is a C function that is close to what you are asking but it takes a bearing and distance. It's in my UtilitiesGeo class on github. You would pass the latitude and longitude from your CLLocation to it and then create a new CLLocation from the resulting lat2 and lon2 that it returns:

/*-------------------------------------------------------------------------
* Given a starting lat/lon point on earth, distance (in meters)
* and bearing, calculates destination coordinates lat2/lon2.
*
* all params in degrees
*-------------------------------------------------------------------------*/
void destCoordsInDegrees(double lat1, double lon1,
                         double distanceMeters, double bearing,
                         double* lat2, double* lon2);

如果你不能使用它,看看它派生自这里的算法这里 也许你可以修改它或那些网站可能有更接近您需求的东西.

If you can't use that, take a look at the algorithms that it was derived from here and here and perhaps you can modify it or those sites might have something closer to your needs.

这篇关于将 CLLocation 移动 x 米的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆