编码:
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([[[NSUserDefaults standardUserDefaults] objectForKey:@"lat"] floatValue], [[[NSUserDefaults standardUserDefaults] objectForKey:@"lon"] floatValue]);
CLLocation *currentLocation = [[CLLocation alloc] initWithCoordinate:coordinate altitude:1 horizontalAccuracy:1 verticalAccuracy:-1 timestamp:nil];
[objects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([self.photos[idx][@"lat"] floatValue], [self.photos[idx][@"lon"] floatValue]);
CLLocation *location = [[CLLocation alloc] initWithCoordinate:coordinate altitude:1 horizontalAccuracy:1 verticalAccuracy:-1 timestamp:nil];
CLLocationDistance distance = [location distanceFromLocation:currentLocation]/1000;
}];
如果我 NSLog currentLocation 和我得到相同坐标的位置,因为它们相同但有细微差别。位置是:lat:37.331581 lon:-122.030708,当前位置是:“lat”:“37.33154”,“lon”:“-122.0307”。正如你所看到的,如果我得到这两个位置的距离,我应该得到 0 公里。但我得到了 12781.989811。这是为什么?我正在运行模拟器。如果是这样,还是我的代码错误?