Convert coordinates to City name?

后端 未结 9 1164
Happy的楠姐
Happy的楠姐 2020-12-02 07:41

How to get an address from coordinates using MapKit?

I have this code when long press on the map it gets the coordinates:

func didLongPressMap(sender         


        
9条回答
  •  春和景丽
    2020-12-02 08:14

    Swift 4.2 Keep it as simple as possible, look at the Apple doc and modify it as you need:

    func retreiveCityName(lattitude: Double, longitude: Double, completionHandler: @escaping (String?) -> Void)
    {
        let geocoder = CLGeocoder()
        geocoder.reverseGeocodeLocation(CLLocation(latitude: latitude, longitude: longitude), completionHandler:
        {
            placeMarks, error in
    
            completionHandler(placeMarks?.first?.locality)
         })
    }
    

提交回复
热议问题