【发布时间】:2014-11-20 21:37:08
【问题描述】:
我正在尝试计算并返回两点之间的距离,但我得到了一个荒谬的数字。我已经尝试了用户定义的 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];
【问题讨论】:
-
可能是因为对于
startLocation,代码将latitude传递给longitude参数。 -
我是个白痴。这是我检查的第一件事,完全错过了。谢谢!!!!!!