2017-03-17 7 views
1

: 난 그냥 GMSMapView에 사용자의 현재 위치 및 업데이트를 추적 CLLocationManagerDelegate 간단한 GMSMapView 구축을 locationManager 파견 큐 문제 내가 만든 것을

.

문제 :

CLLocationManagerDelegate합니다 (GMSMapView 화면)이 잘 작동하지만, 나는 segue를 사용하여 GMSMapView 화면으로 접촉을 시도 할 때 오류가 밀어 직접 열립니다.

주 스레드가 아닌 다른 스레드에서 실행중인 디스패치 큐에 위치 관리자 (0x145e5f9e0)가 생성되었습니다. 위치 관리자 객체가 할당 된 스레드에서 실행 루프가 실행되도록하는 것은 개발자의 책임입니다. 특히 임의의 디스패치 대기열 (기본 대기열에 첨부되지 않음)에서 위치 관리자를 만드는 것은 지원되지 않으며 콜백이 수신되지 않습니다.

답변

2

. 그래서 이슈는 변수 GMSMapViewCLLocationManager의 초기화와 관련이 있습니다. 이것은 나를 위해 일한 방법은 다음과 같습니다

나는

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

아래와 같이 ViewController 클래스의 변수를 정의 그리고 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

사용 스위프트 3을 사용하여이 코드

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

나는 사실상 모든 코드를 ViewController에서 제거했다. 단지'GMSMapView' 인스턴스가 있고 여전히 같은 오류가 발생하고'DispatchQueue'에 추가 할 코드가 남아 있지 않다. –

+0

GMSMapView이 코드에서 작성 –

+0

같은 오류! 'GMSMapView' 구현에 문제가있는 것처럼 보입니다. –