谷歌地图 - reverseGeocodeCoordinate不会在新加坡打印地址

问题描述 投票:1回答:1

我工作的应用程序,它使用谷歌地图,并尝试打印地址。然而,当我将我的周围新加坡地图这是行不通的。我得到了协调,但不打印位置。下面是我的代码。与已经试过

let lines = address.lines

然后打印

self.locationTF.text = lines.joined(separator: "\n")

但该地址仍然没有出现。我的代码工作,当我搬来搬去马来西亚和印尼的地图,而不是在新加坡。有没有人知道为什么出现这种情况?

// Implement Geocoding - show street address
func reverseGeocodeCoordinate(_ coordinate: CLLocationCoordinate2D) {
    self.vc.locationTF.unlock()

    let geocoder = GMSGeocoder()
    print("COORDINATE: ", coordinate)
    geocoder.reverseGeocodeCoordinate(coordinate) { response, error in
        guard let address = response?.firstResult(), let sublocality = address.subLocality, let locality = address.locality, let state = address.administrativeArea else {
            return
        }
        self.vc.locationTF.text = sublocality + ", " + locality + ", " + state
        print("LOCATION: ", sublocality + locality + state)
        UIView.animate(withDuration: 0.25) {
            self.vc.view.layoutIfNeeded()
        }
    }
}
ios swift google-maps reverse-geocoding
1个回答
0
投票

你的后卫只会让你的代码继续,如果所有属性sublocality,地点和administrativeArea不为零。当您在新加坡使用它的属性之一可能无法使用并打印位置之前,你的代码返回。

© www.soinside.com 2019 - 2024. All rights reserved.