Swift 2 Mapkit Get City from user location

swift2 location mapkit

337 просмотра

1 ответ

Is it possible to get the name of the city and put that one into an array of strings from the user location, using Mapkit? I already know how to get the user location so you dont have to go into that.

Автор: Korken55 Источник Размещён: 08.11.2019 11:17

Ответы (1)

1 плюс


Yes you can with using CLGeocoder class try to use this code

 CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: newCoordinates.latitude, longitude: newCoordinates.longitude),             
     completionHandler: {(placemarks, error) -> Void in

            if error != nil {
                print("Reverse geocoder failed with error" + error!.localizedDescription)

            if placemarks!.count > 0 {
                let pm = placemarks![0]

                let c = pm.locality // city of place mark 

            else {
                annotation.title = "Unknown Place"
                print("Problem with the data received from geocoder")
Автор: Hosny Размещён: 20.08.2016 03:52
Вопросы из категории :