我有一个 mapkit View ,数据是从以前的 View 发送到的,这工作正常。我需要了解的是如何将我的源位置设置为用户的当前位置。这是我的代码行:
let sourcelocation = CLLocationCoordinate2D(latitude: track.lat, longitude: track.lon)
let destinationLocation = CLLocationCoordinate2D(latitude: track.lat, longitude: track.lon)
当我运行时,显然这会将 2 个引脚放在完全相同的位置。
我不确定要在 sourceLocation 行中输入什么来显示当前位置。
我的代码中已经有以下几行:
var myLocation:CLLocationCoordinate2D
self.locationManager.requestAlwaysAuthorization()
self.locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
}
并且我已经通过以下方式宣布了我的委托(delegate):
CLLocationManagerDelegate
我只是不确定现在该去哪里。
最终,我试图让它绘制一条路线,并允许您从当前位置导航到目的地位置。
最佳答案
您可以通过 CLLocationManager 获取当前位置坐标:
让 sourcelocation = self.locationManager.location?.coordinate
关于ios - Mapkit 中的当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42810109/