【问题标题】:CLLocationManager not returning correct locationCLLocationManager 没有返回正确的位置
【发布时间】:2013-04-24 21:58:37
【问题描述】:

我正在开发一个应用程序,它每分钟左右检查一次您的位置,看看您的位置是否发生了变化。我正在使用 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);
        }
    } ];

}

无论我更改了多少次位置,它每次都会给我相同的位置,而不是正确的位置。谁能告诉我我做错了什么?

【问题讨论】:

    标签: ios-simulator cllocationmanager cllocation reverse-geocoding clgeocoder


    【解决方案1】:

    它的帖子有点旧,我对 CLLocationManager 的东西有基本的了解,但我仍在努力解决这个问题。我从您上面的代码中了解到 CLLocationManager 每次都会重新创建。 CLLocationManager 就像一个单例类,您不需要每次都重新创建。你只需要调用 [locationManager startUpdatingLocation]; .

    每次调用 [geocoder reverseGeocodeLocation:xxx] 时也是如此。可能您需要在执行此操作之前找到准确性,这样它就不会被一次又一次地调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-28
      • 1970-01-01
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      相关资源
      最近更新 更多