0
我想實現GoogleMaps,但我甚至無法讓CLLocationManager工作。 didUpdateLocations
方法未運行。這是我的控制器:Swift:位置管理員沒有更新位置?
import UIKit
import CoreLocation
import GoogleMaps
...
class RootMapViewController: UIViewController {
let locationManager = CLLocationManager()
@IBOutlet weak var mapView: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
fetchLocation()
...
}
func addMapPin(coordinates: CLLocationCoordinate2D, title: String, description: String) {
...
}
private func fetchLocation() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
}
private func centerMapOn(userCoordinates: CLLocationCoordinate2D) {
...
}
}
// MARK: CLLocationManagerDelegate
extension RootMapViewController: CLLocationManagerDelegate {
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedWhenInUse {
print("gggggggggggggggggg") // <----------------- prints properly ****
locationManager.startUpdatingLocation()
print("hhhhh")
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
}
}
// ISSUE ARISES HERE: *****************************************
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("zzzzzzzzzzzzzzzzzzz") // <----------------- doesn't print ****
let userCoordinates = manager.location!.coordinate
centerMapOn(userCoordinates)
locationManager.stopUpdatingLocation()
}
}
我的Info.plist文件具有關鍵:
更新:
嘗試實際上爲nslocation輸入東西時使用描述 – beyowulf
不幸...我甚至添加了另一個(更新問題的截圖) – Edmund
是否/有警報顯示? – beyowulf