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

时间:2017-12-08 08:55:54

标签: ios swift cllocationmanager cllocation cllocationcoordinate2d

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

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

请帮助我。谢谢

5 个答案:

答案 0 :(得分:1)

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

 location = locations.last!
}

答案 1 :(得分:0)

请在发布前做一些研究。

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

CLLocation Documentation

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

答案 2 :(得分:0)

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

(locations.first?.coordinate)!

答案 3 :(得分:0)

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

答案 4 :(得分:0)

另一种方式:

let lastLocation = locations.flatMap({ $0.coordinate }).last

相关问题