一旦发现用户的位置,使当前位置显示在地图上 swift 3

Make the current location appear on the map once the user’s position has been spotted swift 3

您好,我正在尝试修复这个在 swift 3 之前完全没问题的功能,有人知道有什么变化吗?

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    if !didFindMyLocation {
        let myLocation: CLLocation = change?[NSKeyValueChangeKey] as! CLLocation //Getting an error here Cannot convert value of type '(NSKeyValueChangeKey).Type' (aka 'NSKeyValueChangeKey.Type') to expected argument type 'DictionaryIndex<_, _>'
        viewMap.camera = GMSCameraPosition.camera(withTarget: myLocation.coordinate, zoom: 10.0)
        viewMap.settings.myLocationButton = true

        didFindMyLocation = false
    }

}

您应该提供正确的密钥,如下所示:

let myLocation: CLLocation = change?[NSKeyValueChangeKey.newKey] as! CLLocation