Swift 2 Mapkit 从用户位置获取城市

Swift 2 Mapkit Get City from user location

是否可以使用 Mapkit 获取城市名称并将其放入用户位置的字符串数组中? 我已经知道如何获取用户位置,因此您不必深入研究。

是的,您可以使用 CLGeocoder class 尝试使用此代码

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

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

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

            }
            else {
                annotation.title = "Unknown Place"
                self.outletOfMapView.addAnnotation(annotation)
                print("Problem with the data received from geocoder")
            }
        })