2017-03-17 58 views
1

我已經建立:的LocationManager調度隊列問題

我建立了一個簡單的GMSMapViewCLLocationManagerDelegate,僅僅跟蹤上GMSMapView用戶的當前位置和更新。

問題:

CLLocationManagerDelegate(在GMSMapView屏)直接打開它工作得很好,但是當我試圖達到的GMSMapView屏幕使用segue它會將一個錯誤。

位置管理器(0x145e5f9e0)是在除主線程以外的線程上執行的分派隊列上創建的。開發人員有責任確保在分配了位置管理器對象的線程上運行運行循環。特別是,在任意調度隊列(不附加到主隊列)中創建位置管理器不受支持,並且會導致未收到回調。

回答

2

使用斯威夫特3。所以問題是初始化變量GMSMapViewCLLocationManager。這是如何爲我工作:

我定義的ViewController類變量如下

private var locationManager: CLLocationManager! 
private var googleMapView: GMSMapView! 

而在viewDidLoad()我介紹了一個DispatchQueue在主線程中運行它。

DispatchQueue.main.async { 
     //adding mapView 
     self.googleMapView = GMSMapView() 
     self.view.addSubview(self.googleMapView) 
     self.googleMapView.translatesAutoresizingMaskIntoConstraints = false 
     //auto layout constraints 
     self.googleMapView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0).isActive = true 
     self.googleMapView.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: 0).isActive = true 
     self.googleMapView.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 0).isActive = true 
     self.googleMapView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0).isActive = true 
     //location manager setup 
     self.locationManager = CLLocationManager() 
     self.locationManager.delegate = self 
     self.locationManager.startUpdatingHeading() 
    } 
0

你必須把你的代碼找到調度隊列而不是主隊列。

+0

@約翰Welliem ....請參考以下鏈接 https://www.3pillarglobal.com/insights/blocks-ios-introduction-to-grand-central-dispatch –

+0

請同時參閱本 HTTPS ://www.appcoda.com/ios-concurrency/ –

+0

一個更具體的答案將不勝感激。 –

1

使用此代碼

DispatchQueue.main.async 
{ 
    /*your code here*/ 
}; 
+0

我真的從ViewController中刪除了所有代碼,只有'GMSMapView'實例存在,並且仍然存在相同的錯誤,並且沒有代碼留在'DispatchQueue'中添加。 –

+0

GMSMapView在此代碼中製作 –

+0

同樣的錯誤!似乎GMSMapView'實現有些問題。 –