Reputation: 13
how cat get coordinate location of didUpdateLocation delegate ?
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
Please Help me.Thanks
Upvotes: 1
Views: 319
Reputation: 1144
Another way:
let lastLocation = locations.flatMap({ $0.coordinate }).last
Upvotes: 0
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
Reputation: 56
the simple answer for this question in swift :
(locations.first?.coordinate)!
Upvotes: 0
Reputation: 19750
Please do some research before posting.
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let coordinate = locations.first?.coordinate
}
The location manager gives you an array of locations, just get the first one and then access the coordinate property.
Upvotes: 0
Reputation: 4917
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
location = locations.last!
}
Upvotes: 1