【发布时间】:2015-01-31 20:11:49
【问题描述】:
我无法调用MKMapView 委托方法didUpdateUserLocation。
到目前为止我做了什么:
在项目中添加框架
MapKit.framwork通过
import MapKit线在视图控制器中导入框架-
在plist文件中添加key
<key>NSLocationAlwaysUsageDescription</key> <true/> 视图控制器中的代码
添加了委托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必须是文本,即当系统请求允许使用位置服务时,用户得到的提示问题。
标签: ios swift mapkit xcode6.0.1 mkuserlocation