gpt4 book ai didi

ios - 无法快速使用 CLGeoCoder 获取州和邮政编码?

转载 作者:行者123 更新时间:2023-11-28 08:07:47 25 4
gpt4 key购买 nike

我无法使用 CLGeocoder 获取州和邮政编码。我只获取位置名称、国家和城市。我在印度使用此代码获取位置。我为此使用以下代码。

func getAddressFromLocation(location: CLLocation) {

CLGeocoder().reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
print(location)
self.activityIndicator.stopAnimating()
if error != nil {
DILog.print(items: "Reverse geocoder failed with error" + (error.debugDescription))
return
}

var placeMark: CLPlacemark!
placeMark = placemarks?[0]

if placeMark == nil {
return
}

// Location name
if let locationName = placeMark.addressDictionary!["Name"] as? String {
self.currentLocation = self.currentLocation + locationName
}

// Street address
if let street = placeMark.addressDictionary!["Thoroughfare"] as? String {
self.currentLocation = self.currentLocation + ", " + street
self.spotLocation.street_address_1 = street

}

// City
if let city = placeMark.addressDictionary!["City"] as? String {
print(city, terminator: "")
self.currentLocation = self.currentLocation + ", " + city
self.spotLocation.city = city
}

// Country
if let country = placeMark.addressDictionary!["Country"] as? String {
print(country, terminator: "")
self.currentLocation = self.currentLocation + ", " + country
self.spotLocation.country = country

}
// Street address
if let street1 = placeMark.addressDictionary!["SubThoroughfare"] as? String {
self.currentLocation = self.currentLocation + ", " + street1
self.spotLocation.street_address_1 = street1


}
// state
if let state = placeMark.addressDictionary!["State"] as? String {
self.currentLocation = self.currentLocation + ", " + state
self.spotLocation.state = state
}
// Zip
if let zip = placeMark.addressDictionary!["Zip"] as? String {
self.currentLocation = self.currentLocation + ", " + zip
self.spotLocation.state = zip
}
self.locationLabel.text? = self.currentLocation


})

}

请告诉我如何获得解决方案?

最佳答案

let zipCode = placeMark.postalCode ?? "unknown"

关于ios - 无法快速使用 CLGeoCoder 获取州和邮政编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44617526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com