1

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

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

请帮助我。谢谢

4

5 回答 5

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

 location = locations.last!
}
于 2017-12-08T08:58:49.227 回答
0

请在发布之前做一些研究。

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

CLLocation 文档

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

于 2017-12-08T08:59:07.410 回答
0

快速回答这个问题的简单答案:

(locations.first?.coordinate)!
于 2017-12-08T08:59:20.130 回答
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)
}
于 2017-12-08T08:59:34.933 回答
0

其他方式:

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

于 2017-12-08T09:27:35.450 回答