我無法調用MKMapView
委託方法didUpdateUserLocation
。Swift + didUpdateUserLocation沒有被調用
我做了什麼至今:
添加框架
MapKit.framwork
項目進口框架中的視圖控制器通過
import MapKit
線添加鍵plist文件
<key>NSLocationAlwaysUsageDescription</key> <true/>
012在視圖控制器
代碼
新增委託didUpdateUserLocation
方法來檢查位置更新或沒有,但從來沒有所謂。
// MARK: - MapView delegate methods
func mapView(mapView: MKMapView!, regionDidChangeAnimated animated: Bool) {
// Calling...
}
func mapView(mapView: MKMapView!, didUpdateUserLocation userLocation: MKUserLocation!) {
// Not getting called
}
// MARK: - View lifeCycle methods
override func viewDidLoad() {
super.viewDidLoad()
var locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
self.mapView.delegate = self
self.mapView.showsUserLocation = true
self.mapView.pitchEnabled = true
self.mapView.showsBuildings = true
}
我已經使用模擬器和更改模擬器自定義位置來檢查它是否被調用?方法regionDidChangeAnimated
被稱爲完美!
同樣的事情適用於iOS7。 Swift地圖位置更新還需要做些什麼?
編輯:的plist鍵
也許可警報不會提示。
關鍵'NSLocationAlwaysUsageDescription'的'value'必須是文本,即系統請求使用位置服務許可時提示用戶的問題。 – zisoft 2014-12-03 10:31:19