【问题标题】:[iOS][Background] updating map pins | drawing lines[iOS][后台] 更新地图图钉 |画线
【发布时间】:2013-04-28 16:07:29
【问题描述】:

喂 :)

我正在尝试在后台更新设备 (iPhone) 的位置,它适用于模拟器 http://grab.by/meLq(注释仅在后台添加)。

但是当我用我的 iPhone 进行测试时,它不起作用,我在最后一个位置(在后台之前)和激活时的位置之间有一条线。

编码呢?

当应用程序处于后台并且当应用程序再次变为活动状态时,我进行了创建列表的测试,我加载了记录的位置列表。 (使用模拟器)

    - (void)handleAddLocations {
        NSLog(@"%s | %@", __PRETTY_FUNCTION__, self.locationBackgroundList);

        if ([self.locationBackgroundList count] > 0) {
            for (CLLocation *backgroundLocation in self.locationBackgroundList) {

                if (YES){
                    LocAnnotation* annotation = [[LocAnnotation alloc] initWithCoordinate:backgroundLocation.coordinate];
                    NSLog(@"%s %@", __PRETTY_FUNCTION__, [annotation description]);
                    [self.mapView addAnnotation:annotation];
            }

        MKUserLocation *userLocation = [[MKUserLocation alloc] init];
        [userLocation setCoordinate:backgroundLocation.coordinate];

        [self mapView:self.mapView didUpdateUserLocation:userLocation];

         }
        [self.mapView updateConstraints];

        [self.locationBackgroundList removeAllObjects];
        self.locationBackgroundList = [[NSMutableArray alloc] init];
      }
  }

感谢您的帮助;)

【问题讨论】:

  • 你是如何设置 CLLocationManager 的?
  • - (void)setup { self.locationManager = [CLLocationManager new]; self.locationManager.delegate = self; self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; self.isUpdatingLocation = NO; }

标签: ios objective-c map annotations line


【解决方案1】:

通过在后台创建位置列表来添加注释是一个更好的选择。当应用程序在后台时,这是无法管理 uielements 的。为此,您应该在应用程序在时添加数组中的所有位置背景。

【讨论】:

  • 现在它正在工作我必须在主线程上添加位置 [self performSelectorOnMainThread:@selector(handleAddLocations) withObject:nil waitUntilDone:NO];
  • 此外,模拟器一切正常,但我的手机精度很差,比如 200 米。 有什么想法吗?
  • 对于位置管理器,您应该将准确度设置为最佳,然后您将获得准确的结果。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多