2012-10-04 43 views
1

我可以删除所需点的两个注释(源,目标)。但是,现在我想确定它们之间的距离。我寻找解决方案,并在跨越一个传来: Calculating distance between two points计算两个注释之间的距离:iOS 5

但解决的办法:

CLLocationDistance distance = [location1 getDistanceFrom:location2]; 

getDistanceFrom:中的iOS 5已弃用请任何人可以建议我的方式来做到这一点使用谷歌地图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); 
:找点

之间的实际距离而查找的选项,我碰到另一种解决方案来

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

在此先感谢

+1

distanceFromLocation使用一条直线(沿地球表面),而不是一条公路。 http://developer.apple.com/library/ios/DOCUMENTATION/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/occ/instm/CLLocation/distanceFromLocation: – Craig

+0

请给我一种我可以使用的方式在寻找沿路的距离 – iDev

回答

3

如何distanceFromLocation:

Source

+0

我试过了:CLLocationDistance distance = [location distanceFromLocation:location2]; NSLog(@“Distance is:%f”,distance); 但它返回0.00000 – iDev

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]; 
相关问题