user9071596
user9071596

Reputation: 13

how convert locations: [CLLocation] to Coordinate2D?

how cat get coordinate location of didUpdateLocation delegate ?

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

Please Help me.Thanks

Upvotes: 1

Views: 319

Answers (5)

orxelm
orxelm

Reputation: 1144

Another way:

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

Upvotes: 0

Nirmalsinh Rathod
Nirmalsinh Rathod

Reputation: 5186

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

Upvotes: 0

faez.ham
faez.ham

Reputation: 56

the simple answer for this question in swift :

(locations.first?.coordinate)!

Upvotes: 0

Scriptable
Scriptable

Reputation: 19750

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.

Upvotes: 0

Uma Madhavi
Uma Madhavi

Reputation: 4917

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

 location = locations.last!
}

Upvotes: 1

Related Questions