如何获得目标 c 中两个位置之间的距离(以英里为单位)?

发布于 2024-12-10 11:47:49 字数 94 浏览 0 评论 0原文

如何使用 Mapkit 框架的 distanceFromLocation 方法计算两个位置之间的距离(以英里为单位)。

谢谢

how to calculate distance between two location in miles using distanceFromLocation method of mapkit framework.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

为人所爱 2024-12-17 11:47:49

这个问题已经在此处的指标中得到了回答。现在您只需将米转换为英里,即:

1 Meter = 0.000621371192 Miles 

1 Mile = 1609.344 Meters 

This has already been answered in metric here. Now you just need to convert meters to miles which is:

1 Meter = 0.000621371192 Miles 

or

1 Mile = 1609.344 Meters 
听不够的曲调 2024-12-17 11:47:49

尝试下面的代码:

double latA = [currentlat floatValue];
double logA = [currentlong floatValue];

double latB = [toLat floatValue];
double logB = [toLong floatValue];

CLLocation *locA = [[CLLocation alloc] initWithLatitude:latA
                                              longitude:logA];

CLLocation *locB = [[CLLocation alloc] initWithLatitude:latB longitude:logB];
CLLocationDistance distance = [locA distanceFromLocation:locB];
NSLog(@"Calculated Miles %@", [NSString stringWithFormat:@"%.1fmi",(distance/1609.344)]);

Try below code:

double latA = [currentlat floatValue];
double logA = [currentlong floatValue];

double latB = [toLat floatValue];
double logB = [toLong floatValue];

CLLocation *locA = [[CLLocation alloc] initWithLatitude:latA
                                              longitude:logA];

CLLocation *locB = [[CLLocation alloc] initWithLatitude:latB longitude:logB];
CLLocationDistance distance = [locA distanceFromLocation:locB];
NSLog(@"Calculated Miles %@", [NSString stringWithFormat:@"%.1fmi",(distance/1609.344)]);
我们只是彼此的过ke 2024-12-17 11:47:49

这个函数在苹果的文档中似乎相当不言自明?它将给出用户位置和给定位置之间的距离,因此您必须创建一个新的 CLLocation 对象来告诉 iPhone 您想去哪里。

该函数给出的结果以米为单位。要转换为英里,请乘以 0.000621371192。 此帖子中提供了更多信息。

The function seems fairly self explanatory in Apple's documentation? It will give the distance between the user's location and the location given, so you'd have to create a new CLLocation object to tell the iPhone where you want to go.

The function gives the result in meters. To convert to miles, multiply by 0.000621371192. More information is given in this thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文