如何将位置:[CLLocation] 转换为 Coordinate2D?

how convert locations: [CLLocation] to Coordinate2D?

cat 如何获取 didUpdateLocation 委托的坐标位置?

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) 

请帮忙me.Thanks

 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

 location = locations.last!
}

发帖前请做一些研究。

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let coordinate = locations.first?.coordinate
}

CLLocation Documentation

位置管理器为您提供位置数组,只需获取第一个位置,然后访问坐标 属性。

swift 中这个问题的简单答案:

(locations.first?.coordinate)!
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: AnyObject[]!) {
        var locationArray = locations as NSArray
        var locationObj = locationArray.lastObject as CLLocation
        var coord = locationObj.coordinate

        println(coord.latitude)
        println(coord.longitude)
}

另一种方式:

let lastLocation = locations.flatMap({ [=10=].coordinate }).last