我试图在选择时将MKMapView置于注释的坐标上
mapView.setCenterCoordinate(annotation.coordinate, animated: true)
。
然而,地图反而(并且始终如一)将注释大约100px垂直偏离中心。
在
mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool)
我正在做一些调试日志来说明问题。
The coordinate I'm attempting to center on.
将中心坐标设置为CLLocationCoordinate2D(纬度:40.7197525,经度:-73.9896055)
The map's bounds (this is the expected value).
(lldb)po mapView.bounds (origin =(x = 0,y = 0),size =(width = 375,height = 503))
The map's center (this is the expected value, i.e. the map isn't bigger than expected).
(lldb)po mapView.bounds.center (x = 187.5,y = 251.5)
The maps center coordinate (also expected).
(lldb)po mapView.centerCoordinate (纬度= 40.719752499999998,经度= -73.98960550000001)
Ask the map to convert it's center coordinate to view points (NOT the expected value).
(lldb)po mapView.convertCoordinate(mapView.centerCoordinate,toPointToView:mapView) (x = 187.5,y = 358.49999999998431)
Ask the map to convert it's bounds center to map coordinates (this matches what is displayed).
(lldb)po mapView.convertPoint(mapView.bounds.center,toCoordinateFromView:mapView) (纬度= 40.747910796601502,经度= -73.98960550000001)
我期望发生的是,在调用setCenterCoordinate:
(并且动画完成)后,提供的坐标大致位于MKMapView
的中心。相反,我希望将地图的centerCoordinate
点转换为视图坐标convertCoordinate
将大致匹配mapView.bounds.center
的值。任何洞察这个额外偏移的来源都将非常赞赏。