我已经在这里进行了研究,以尝试解决我的问题,但是我似乎找不到解决方案。我希望地图旋转,所以屏幕的顶部是用户的行进方向。下面的代码有效,但会根据手机所面对的方向旋转屏幕。我只希望地图在用户朝不同方向移动时旋转。
有人解决了这个问题吗?
let manager = CLLocationManager()
@IBOutlet weak var map: MKMapView!
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading){
map.camera.heading = newHeading.magneticHeading
map.setCamera(map.camera, animated: true)
print("updatingHeading is called")
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
let span:MKCoordinateSpan = MKCoordinateSpan.init(latitudeDelta: 0.01,longitudeDelta: 0.01)
let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude,location.coordinate.longitude)
let region:MKCoordinateRegion = MKCoordinateRegion.init(center: myLocation, span: span)
map.setRegion(region, animated: true)
self.map.showsUserLocation = true
let mapCamera = MKMapCamera(lookingAtCenter: myLocation, fromDistance: 5000, pitch: 30, heading: 0)
map.setCamera(mapCamera, animated: true)
}
func viewDidLoad() {
manager.startUpdatingLocation()
manager.startUpdatingHeading()
}
swift中有什么可以帮助我的吗?
欢呼