cat 如何获取 didUpdateLocation 委托的坐标位置?
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
请帮助我。谢谢
cat 如何获取 didUpdateLocation 委托的坐标位置?
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
请帮助我。谢谢
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
location = locations.last!
}
请在发布之前做一些研究。
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let coordinate = locations.first?.coordinate
}
位置管理器为您提供一组位置,只需获取第一个位置,然后访问坐标属性。
快速回答这个问题的简单答案:
(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({ $0.coordinate }).last