总是从 CLLocationManager 获得相同的坐标

Posted

技术标签:

【中文标题】总是从 CLLocationManager 获得相同的坐标【英文标题】:always get same coordinates from CLLocationManager 【发布时间】:2013-02-24 10:11:42 【问题描述】:

我想使用 CLLocationManager 来获取每次点击按钮时的当前位置,但始终获得相同的坐标:(

- (void)GetCoord

    self.currentLocation = nil;

    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [self.locationManager startUpdatingLocation];


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 

    self.currentLocation = newLocation;

    UIAlertView *alert = [[UIAlertView alloc] 
        initWithTitle:@"Megerősítés" 
        message:[NSString stringWithFormat:@"%f ::: %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude] 
        delegate:self 
        cancelButtonTitle:@"Nem" 
        otherButtonTitles:nil
    ];

    [alert show];
    [self.locationManager stopUpdatingLocation];

【问题讨论】:

你是通过模拟器运行这个吗?也许您正在模拟该位置。检查调试器上方 Xcode 中的小当前位置图标。 【参考方案1】:
  -(void) updateLocation
    
        [locationManager startUpdatingLocation];
    



- (void)locationManager:(CLLocationManager *)manager
        didUpdateToLocation:(CLLocation *)newLocation 
               fromLocation:(CLLocation *)oldLocation
    
        userLocation.latitude = newLocation.coordinate.latitude;
        userLocation.longitude = newLocation.coordinate.longitude;

        [locationManager stopUpdatingLocation];
        //Send any notification to your controller about the update location.
    

【讨论】:

以上是关于总是从 CLLocationManager 获得相同的坐标的主要内容,如果未能解决你的问题,请参考以下文章

CLLocationManager 提供旧位置。如何获得新位置?

我多久可以从 CLLocationManager 获得更新?

CLLocationManager 在蜂窝网络 (3G) 中未获得位置准确性

CLLocationManager 确保 iphone 的最佳准确性

CLLocationManager 最后一个已知位置

CLLocationManager 奇怪的行为