【发布时间】:2016-07-09 06:54:44
【问题描述】:
我想在地图上显示代表用户位置的蓝点。
我试过这样做:
override func viewWillAppear(animated: Bool) {
self.mapView.addObserver(self, forKeyPath: "myLocation", options: NSKeyValueObservingOptions.New, context: nil)
}
deinit {
self.mapView.removeObserver(self, forKeyPath: "myLocation")
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if keyPath == "myLocation" {
self.mapView.animateToLocation((object?.myLocation!!.coordinate)!)
self.mapView.animateToZoom(17)
}
}
但是observeValueForKeyPath(keyPath: ofObject: change: context:) 没有打电话,我不明白为什么。
非常感谢!
【问题讨论】:
标签: ios iphone swift cocoa-touch google-maps-sdk-ios