Swift 3 随用户方向旋转地图
Swift 3 Rotate Map With User Direction
目前我的 swift 应用程序有一个带有各种注释的地图视图,当用户从地图上的各种注释行走时,有没有办法不总是锁定在北方方向?我希望地图转向他们行走的方向,而不是总是指向北方。
这是我当前的 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)
}
我应该在这里申报吗?
此示例会将 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)
}
}
这就是你想要的吗?希望对您有所帮助 :)
目前我的 swift 应用程序有一个带有各种注释的地图视图,当用户从地图上的各种注释行走时,有没有办法不总是锁定在北方方向?我希望地图转向他们行走的方向,而不是总是指向北方。
这是我当前的 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)
}
我应该在这里申报吗?
此示例会将 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)
}
}
这就是你想要的吗?希望对您有所帮助 :)