【问题标题】:current location in mapkitmapkit 中的当前位置
【发布时间】:2017-03-15 12:42:25
【问题描述】:

我有一个 mapkit 视图,数据从前一个视图发送到该视图,这工作正常。我需要了解的是如何将我的源位置设置为用户的当前位置。这是我的代码行代码:

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()
}

我已经声明了我的代表:

CLLocationManagerDelegate

我只是不知道现在该去哪里。

最终我试图让它绘制一条路线并允许您从当前位置导航到目标位置。

【问题讨论】:

    标签: ios swift xcode mapkit


    【解决方案1】:

    您可以通过 CLLocationManager 获取当前位置坐标:

    让 sourcelocation = self.locationManager.location?.coordinate

    【讨论】:

      【解决方案2】:

      由于您使用的是 MapKit,因此您可能在某个时候实现了 MapView。如果有意义,您可以使用

      mapView.userLocation.location
      

      获取设备的位置。

      【讨论】:

        猜你喜欢
        • 2012-11-20
        • 1970-01-01
        • 2017-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多