代码之家  ›  专栏  ›  技术社区  ›  mastercoder

CLLocationManager能否在swift 3中同时管理2个或多个位置

  •  0
  • mastercoder  · 技术社区  · 8 年前

    我有一个问题,我似乎在任何地方都找不到答案,我在viewController中有一个全局CLLocationManager()变量,这样我就可以看到用户何时通过locationManager回调进入或离开一个位置,它一次只在一个位置上完美工作,但我想让应用程序同时监视两个或多个位置。 我创建了一个函数来启动它:

      var coreLocationManger = CLLocationManager()
    
      func setMonitoredRegion(location:CLLocation) {
    
        let startLocation = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
        let monitoredRegion = CLCircularRegion(center: startLocation, radius: 100, identifier: "Local Region")
    
            coreLocationManger.startMonitoring(for: monitoredRegion)
            coreLocationManger.allowsBackgroundLocationUpdates = true
    
            coreLocationManger.delegate = self
            monitoredRegion.notifyOnEntry = true
            monitoredRegion.notifyOnExit = true
    
    }
    

    这个函数要求管理一个位置,当我对不同的位置多次使用它时,它只管理最后一个给定的位置! 你们有什么建议吗? 非常感谢。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Alex Pavlov    8 年前

    每次调用函数时都会覆盖该区域。确保每个位置的区域标识符不同。