Saya menggunakan peta google di Xcode 9 beta, iOS 11.
Saya mendapatkan kesalahan yang dikeluarkan ke log sebagai berikut:
Pemeriksa Utas Utama: API UI memanggil utas latar belakang: - [UIApplication applicationState] PID: 4442, TID: 837820, Nama utas: com.google.Maps.LabelingBehavior, Nama antrean: com.apple.root.default-qos.overcommit , QoS: 21
Mengapa ini terjadi karena saya hampir yakin saya tidak mengubah elemen antarmuka apa pun dari utas utama dalam kode saya.
override func viewDidLoad() {
let locationManager = CLLocationManager()
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
}
viewMap.delegate = self
let camera = GMSCameraPosition.camera(withLatitude: 53.7931183329367, longitude: -1.53649874031544, zoom: 17.0)
viewMap.animate(to: camera)
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
}
func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
}
func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
if(moving > 1){
moving = 1
UIView.animate(withDuration: 0.5, delay: 0, animations: {
self.topBarConstraint.constant = self.topBarConstraint.constant + (self.topBar.bounds.height / 2)
self.bottomHalfConstraint.constant = self.bottomHalfConstraint.constant + (self.topBar.bounds.height / 2)
self.view.layoutIfNeeded()
}, completion: nil)
}
moving = 1
}
// Camera change Position this methods will call every time
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
moving = moving + 1
if(moving == 2){
UIView.animate(withDuration: 0.5, delay: 0, animations: {
self.topBarConstraint.constant = self.topBarConstraint.constant - (self.topBar.bounds.height / 2)
self.bottomHalfConstraint.constant = self.bottomHalfConstraint.constant - (self.topBar.bounds.height / 2)
self.view.layoutIfNeeded()
}, completion: nil)
}
DispatchQueue.main.async {
print("Moving: \(moving) Latitude: \(self.viewMap.camera.target.latitude)")
print("Moving: \(moving) Longitude: \(self.viewMap.camera.target.longitude)")
}
}
mapView(_:didChange)
Anda mengirimkanprint
pernyataan ke antrian utama. Apakah Anda belum berada di antrian utama? Jika tidak, Anda juga harus mengirimkananimate
panggilan ke antrean utama. Saya sarankan untuk memasukkan beberapadispatchPrecondition(condition: .onQueue(.main))
sebelum pembaruan UI tersebut, hanya untuk memastikan.