我正在开发一个应用程序,它每分钟左右检查一次您的位置,看看您的位置是否发生了变化。我正在使用 xCode 中的模拟位置来模拟位置变化。首先我会做伦敦,然后当它更新时我会将它更改为东京之类的东西,然后当它再次检查位置时它不会更新,它仍然认为它在伦敦。
-(void)recheckLocation{
locationManager = nil;
[recheckLocation invalidate];
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
geocoder = [[CLGeocoder alloc] init];
[locationManager stopUpdatingLocation];
// Reverse Geocoding
[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks objectAtIndex:0];
NSString *Location = [NSString stringWithFormat:@"%@, %@",placemark.locality, placemark.administrativeArea];
recheckLocation = [NSTimer scheduledTimerWithTimeInterval:60.0f target:self selector:@selector(recheckLocation) userInfo:nil repeats:YES];
} else {
NSLog(@"%@", error.debugDescription);
}
} ];
}
无论我更改了多少次位置,它每次都会给我相同的位置,而不是正确的位置。有人可以告诉我我做错了什么吗?