我试图计算并返回两点之间的距离,我得到一个荒谬的数字。我已经尝试了用户定义的hasrsine方法和distanceFromLocation方法,并且它们都返回10282657.652 ...对于lat = 32.60641072 / lon = -85.48713530和lat = 32.605638以及lon = -85.486890之间的距离。这些距离太近了吗?
CLLocation *startLocation = [[CLLocation alloc] initWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.latitude];
CLLocation *endLocation = [[CLLocation alloc] initWithLatitude:_head.lattitude longitude:_head.longitude];
double distance = [startLocation distanceFromLocation:endLocation];
CLLocationCoordinate2D newCoordinate = [startLocation coordinate];
CLLocationCoordinate2D oldCoordinate = [endLocation coordinate];
double distance2 = [self distanceFrom:newCoordinate to:oldCoordinate];
NSNumber *myDoubleNumber = [NSNumber numberWithDouble:distance2];
_charLabel.text = [myDoubleNumber stringValue];
答案 0 :(得分:0)
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:lon1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:lon2];
CLLocationDistance distance= [location1 distanceFromLocation:location2]*1.09361;
"距离"将返回米。 这段代码对我有用:)