我怎样才能得到两个CLLocation
之间以米为单位的距离呢?CLLocation
没有提供任何这样做的方法,它看起来。
发布于 2012-05-03 21:09:01
CLLocationDistance distance = [aCLLocationA distanceFromLocation:aCLLocationB];
// distance is a double representing the distance in meters
发布于 2012-05-03 21:08:24
CLLocationDistance distance = [secondLocation distanceFromLocation:firstLocation]; // distance is expressed in meters
CLLocationDistance kilometers = distance / 1000.0;
// or you can also use this..
CLLocationDistance meters = distance;
NSString *distanceString = [[NSString alloc] initWithFormat: @"%f", kilometers];
flot totaldistancecovered = [distanceString floatValue];
//Now,you can use this float value for addition...
// distanceMoved should be float type variable which is declare in .h file...
distanceMoved = distanceMoved + totaldistancecovered ;
theLabel.text = [NSString stringWithFormat: @"%f meters", distanceMoved];
希望这能帮到你。
发布于 2012-05-03 21:09:36
CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:dblLatitude longitude:dblLongitude];
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:dblCurrentLatitude longitude:dblCurrentLongitude];
double dMeters = [loc1 distanceFromLocation:loc2];
[loc1 release];
[loc2 release];
https://stackoverflow.com/questions/10432023
复制相似问题