how convert locations: [CLLocation] to Coordinate2D?

319 Views Asked by At

how cat get coordinate location of didUpdateLocation delegate ?

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

Please Help me.Thanks

5

There are 5 best solutions below

2
On BEST ANSWER

the simple answer for this question in swift :

(locations.first?.coordinate)!
0
On
 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

 location = locations.last!
}
0
On

Please do some research before posting.

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

CLLocation Documentation

The location manager gives you an array of locations, just get the first one and then access the coordinate property.

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

Another way:

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