Я пытаюсь использовать corelocation в самом начале моего приложения, чтобы получить начальное местоположение.
У меня есть метод делегата:
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSDate* eventDate = newLocation.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
DLog(@"received location data from %f ago, lat/long - %+.6f, %+.6f\nold lat/long %+.6f, %+.6f\nhorizontal accuracy is %f",
howRecent, newLocation.coordinate.latitude, newLocation.coordinate.longitude,
oldLocation.coordinate.latitude, oldLocation.coordinate.longitude,
newLocation.horizontalAccuracy);
// check if new update is significantly different from old one. If it is, then reverse-geocode.
if ([newLocation respondsToSelector:@selector(distanceFromLocation:)]) {
DLog(@"distance from old to new location - %f", [newLocation distanceFromLocation:oldLocation]);
if ([newLocation distanceFromLocation:oldLocation] < 1000) {
// reverse geocode please
[self stopLocationManager];
}
}
else if ([newLocation respondsToSelector:@selector(getDistanceFrom:)]){
DLog(@"distance from old to new location - %f", [newLocation getDistanceFrom:oldLocation]);
if ([newLocation getDistanceFrom:oldLocation] < 1000) {
// reverse geocode please
[self stopLocationManager];
}
}
}
Вот вывод журнала:
... -[AppHelper locationManager:didUpdateToLocation:fromLocation:] received location data from -13.261873 ago, lat/long - +37.705413, -121.866296
old lat/long +0.000000, +0.000000
horizontal accuracy is 1982.000000
... -[AppHelper locationManager:didUpdateToLocation:fromLocation:] distance from old to new location - -1.000000
Есть идеи, почему начальный расчет расстояния от нового местоположения до старого (0,0) дает -1 результат?