我有一个问题,使地图自动跟踪与用户的标题。我已经要求所有必要的授权,并能够捕获用户的位置信息。我目前正在调用此函数,以用户的位置为中心,并且它正在工作。如果我添加包含map.setUserTrackingMode的行,就会出现错误。
我是不是遗漏了什么?
我正在使用的代码:
func centerMapOnLocation(location: CLLocation) {
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, regionRadius, regionRadius)
map.setRegion(coordinateRegion, animated: true)
map.setUserTrackingMode(MKUserTrackingMode.FollowWithHeading, animated: true)
}调用此函数的代码:
func mapView(mapView: MKMapView, didUpdateUserLocation userLocation: MKUserLocation) {
if let loc = userLocation.location {
centerMapOnLocation(loc)
}
}发布于 2016-01-19 22:15:19
可能是setUserTrackingMode在干涉setRegion。这两种方法都以位置为中心,尝试推迟设置跟踪模式,就像这里建议的那样,https://stackoverflow.com/a/16617914/5806210,或者您也可以使用一个特殊的按钮MKUserTrackingBarButtonItem来实现跟踪模式。
https://stackoverflow.com/questions/34887447
复制相似问题