作者:哈行小DWW_421 | 来源:互联网 | 2023-02-05 13:26
目前,我的swift应用程序具有一个带有各种注释的mapview,当用户从地图上的各种注释中走来时,总是不能向北锁定吗?我希望地图转向他们正在走的方向,而不是始终指向北。
这是我当前的updatelocation函数
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations[0]
let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, noteTime.span)
map.setRegion(region, animated: true)
self.map.showsUserLocation = true
map.tintColor = UIColor(red:0.19, green:0.69, blue:0.73, alpha:1.0)
}
我应该在这里声明吗?
1> David Willia..:
本示例将更新旋转,mapView
使其指向与用户相同的方向。
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
let locatiOnManager= CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.startUpdatingHeading()
}
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
mapView.camera.heading = newHeading.magneticHeading
mapView.setCamera(mapView.camera, animated: true)
}
}
那是你的追求吗?希望对您有所帮助:)
如何旋转图钉而不是地图?