1

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

但解决方案:

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);

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

提前致谢

4

2 回答 2

3

怎么样distanceFromLocation:

资源

于 2012-10-04T04:19:24.953 回答
3

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];
于 2015-09-16T09:05:10.460 回答