2017-07-19 39 views
0

我有一個問題,我無法在任何地方找到答案,我在viewController中有一個全局CLLocationManager()變量,以便我可以看到當用戶使用locationManager的callBacks進入或離開某個位置時,它一次只能在一個位置完美運行,但我想讓應用程序同時監視2個或更多的位置。 我創建了一個函數來啓動它:CLLocationManager是否可以在swift中同時管理2個或多個位置3

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 

} 

本功能,要求提供一個位置來管理,當我這個多次與不同的地點使用,它只是管理着被賦予了最後一個位置! 你們有任何提示嗎? 謝謝

回答

0

您每次調用函數時都會覆蓋區域。確保每個位置的地區標識符不同。

+0

這將是有道理的,我即將嘗試它,並回來一些反饋謝謝! :) – mastercoder

+0

它工作非常感謝:) – mastercoder

+0

我很高興它幫助。你介意將答案標記爲正確答案嗎? –

相關問題