我正在使用CLLocation来计算当前用户位置与标注之间的距离。不过我只是想知道这是否正确。目前我正在使用iPhone模拟器进行测试,根据MKMapView显示,iPhone模拟器位于这里:
Lat: 0 Long: -1067024384
注释的位置是:
workingCoordinate.latitude = 40.763856;
workingCoordinate.longitude = -73.973034;
然而,如果你在谷歌地图上查看,你会发现这些距离是多么接近,但根据CLLocation来说是远离的。我正在使用以下代码来确定它们之间的距离。
CLLocation *loc = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude];
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:self.mapView.userLocation.coordinate.latitude longitude:self.mapView.userLocation.coordinate.longitude];
CLLocationDistance dist = [loc distanceFromLocation:loc2];
int distance = dist
NSLog(@"%i", distance);
被NSLog记录的距离为12769908。我认为这是不正确的,因此我的代码肯定出了问题。
如果有问题,请指出来!
ANNO = 37.331741, -122.030564 USER = -180.000000, -180.000000 LOC = 37.331741, LOC2 = -180.000000, -180.000000 LOC2 = -180.000000, -180.000000 DIST: 12769908.162754
- max_