如何在使用reverseGeocodeLocation Swift时找到最近的位置

时间:2016-02-06 23:51:12

标签: ios swift reverse-geocoding clplacemark

我正在使用reverseGeocodeLocation,有时使用给定的纬度和经度,不会返回'subThoroughfare'和'通道'。如果有办法将最近的'subThoroughfare'和'通道'送到那个地方?

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

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

            }

        })

0 个答案:

没有答案