1

我正在使用 reverseGeocodeLocation,有时在给定的纬度和经度下,不会返回“subThoroughfare”和“thoroughfare”。如果有办法获得离该位置最近的“subThoroughfare”和“thoroughfare”?

到目前为止,这是我的代码:

var nearAddressString = ""

        CLGeocoder().reverseGeocodeLocation(userCLLocation, completionHandler: { (placemarks, error) -> Void in

            if error != nil {
                print(error!)

            } else {

                if let p = placemarks?[0] {

                    let subThroughfare = p.subThoroughfare ?? ""

                    let thoroughfare = p.thoroughfare ?? ""

                    let subLocality = p.subLocality ?? ""

                    let subAdministrativeArea = p.subAdministrativeArea ?? ""

                    let postalCode = p.postalCode ?? ""

                    nearAddressString = "\(subThroughfare) \(thoroughfare) \n \(subLocality) \n \(subAdministrativeArea) \n \(postalCode)"

                    print(nearAddressString)

                } else {
                    print("Problem with the data received from geocoder")
                }

            }

        })
4

0 回答 0