首页 文章

didUpdateToLocation不会立即被调用

提问于
浏览
1

我在用

startMonitoringSignificantLocationChanges

得到(lat,lon)值 . 我的问题是

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

在遇到 [locationMangerObject startMonitoringSignificantLocationChanges]; 之后,方法不会被立即调用 . 内部 didUpdateToLocation 方法只保留两个全局双变量来保存纬度和经度,这些变量将从 didUpdateToLocation 方法获得的坐标设置 . 这些值被传递给web服务,因为didUpdateToLocation是仅调用某个延迟,在此延迟之间,(lat,lon)的参数将零作为其值并传递给服务,从而导致意外响应 .

怎么做

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

在`[locationMangerObject startMonitoringSignificantLocationChanges]之后立即调用的方法;遇到了 .

请有人建议我解决这个问题的解决方案 .

提前致谢 .

3 回答

  • 1

    也许您应该考虑使用startUpdatingLocation方法而不是startMonitoringSignificantLocationChanges . 来自iOS文档:

    startUpdatingLocation

    This method returns immediately. 调用此方法会导致位置管理器获取初始位置修复(可能需要几秒钟)并通过调用其locationManager:didUpdateToLocation:fromLocation:method来通知您的委托 .

  • 0

    可能需要几秒到几分钟才能获得一个好位置,具体取决于您是否有无线连接或无线连接,以及您是否有来自GPS卫星的良好信号 . 但是,您应该立即获得缓存(可能过时)的位置 .

    您是否为locationMangerObject设置了委托?

    在调用startMonitoringSignificantLocationChanges后,您的函数是否返回到runloop?

  • 5
    ///Hmmmmm
    
                ...CLLocationManager does n't call delegate method properly 
                ...after lot of R&D I'm  using a watchdog method it calls " -(void)locationadd " function every 10seconds and i'm using that location for drawing the path.
    
      -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
         {
         }       
    
    
    
     - (void)viewDidLoad
         {
    
       [NSTimer scheduledTimerWithTimeInterval:10
                                             target:self
                                               selector:@selector(locationadd)
                                               userInfo:nil
                                               repeats:YES];
    
            }
    
    
            -(void)locationadd   
            {
    
             if ([locationManager location]) {
    
    
    
            //i'm saving this location
    
        CLLocation *locat=locationManager.location;
    
         }
    
            }
            //
    

相关问题