CLLocationManager不能返回正确的位置

问题描述:

我正在开发一款应用程序,它每隔一分钟左右检查一次您的位置,以查看您的位置是否发生了变化。我通过使用xCode中的模拟位置来模拟位置更改。首先我会去伦敦,然后当它更新时,我会把它改成东京这样的东西,然后当再次检查位置的时候它不会更新,它仍然认为它在伦敦。CLLocationManager不能返回正确的位置

-(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); 
     } 
    } ]; 

} 

无论我改变位置多少次,它只是每次给我相同的位置,而不是正确的位置。有人能告诉我我做错了什么吗?

它的一些旧的文章,我有CLLocationManager的东西的基本知识,但我仍然试图解决这个问题。从上面的代码我明白,CLLocationManager是每次都重新创建。 CLLocationManager就像一个你不需要每次重新创建的单例类。你只需要调用[locationManager startUpdatingLocation]; 。

此外,您每次调用[geocoder reverseGeocodeLocation:xxx]。在你这样做之前,你可能需要找到准确性,这样才不会一次又一次地被调用。