【问题标题】:Calculating the distance between two annotations: iOS 5计算两个注解之间的距离:iOS 5
【发布时间】:2012-10-04 04:17:42
【问题描述】:

我可以为所需的点删除两个注释(源、目标)。但是,现在我想确定它们之间的距离。我寻找解决方案并遇到了一个: Calculating distance between two points

但解决方案:

CLLocationDistance distance = [location1 getDistanceFrom:location2];

getDistanceFrom: 在 iOS 5 中已弃用。请任何人建议我使用 Google Maps API 查找点之间的实际距离的方法

在寻找选项时,我遇到了另一个解决方案:

CLLocation *locA = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];

        CLLocation *locB = [[CLLocation alloc] initWithLatitude:coordinate2.latitude longitude:coordinate2.longitude];

        CLLocationDistance distance = [locA distanceFromLocation:locB];
        NSLog(@"DISTANCE : %f", distance/1000);

但是,我不确定这个解决方案是否正确。它返回的距离是公路的源头和目的地之间的实际距离吗?我尝试在谷歌地图上比较它,它大致匹配。请验证它是否正确?

提前致谢

【问题讨论】:

标签: google-maps ios5 mapkit xcode4.3 cllocation


【解决方案1】:

distanceFromLocation:怎么样?

Source

【讨论】:

  • 我试过了:CLLocationDistance distance = [location distanceFromLocation:location2]; NSLog(@"距离为:%f", 距离);但它返回 0.00000
【解决方案2】:

distanceFromLocation:方法在我的代码中运行良好

** 以米为单位的距离显示

 CLLocation *location =[[CLLocation alloc] initWithLatitude:[@"23.039698" doubleValue] longitude:[@"72.571663" doubleValue]];
 CLLocation *loc = [[CLLocation alloc] initWithLatitude:[@"23.0422" doubleValue] longitude:[@"72.5644" doubleValue]];
 CLLocationDistance distanceMeter = [location distanceFromLocation:loc];

【讨论】:

    猜你喜欢
    • 2021-05-15
    • 1970-01-01
    • 1970-01-01
    • 2021-01-14
    • 2010-10-30
    • 1970-01-01
    • 2020-02-12
    相关资源
    最近更新 更多