Überprüfen Sie den folgenden Code für separates Land von Adresse in Google Place Picker api in Swift. es funktioniert für mich !!!
placesClient?.currentPlaceWithCallback({
(placeLikelihoodList: GMSPlaceLikelihoodList?, error: NSError?) -> Void in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
return
}
if let placeLikelihoodList = placeLikelihoodList {
let place = placeLikelihoodList.likelihoods.first?.place
if let place = place {
self.mapView.removeAnnotations(self.mapView.annotations)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: locValue, span: span)
self.mapView.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = locValue
annotation.title = place.name
annotation.subtitle = place.formattedAddress!.componentsSeparatedByString(", ").joinWithSeparator(",")
self.mapView.addAnnotation(annotation)
let arrays : NSArray = place.addressComponents!;
for i in 0..<arrays.count {
let dics : GMSAddressComponent = arrays[i] as! GMSAddressComponent
let str : NSString = dics.type
if (str == "country") {
print("Country: \(dics.name)")
}
else if (str == "administrative_area_level_1") {
print("State: \(dics.name)")
}
else if (str == "administrative_area_level_2") {
print("City: \(dics.name)")
}
}
}
}
})
, warum Sie nicht Reverse-Geokodierung mit dem Breitengrad verwenden und Länge Sie –
erhalten https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLGeocoder_class/#//apple_ref/occ/instm/CLGeocoder/reverseGeocodeLocation: completionHandler: –
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLPlacemark_class/index.html#//apple_ref/occ/instp/CLPlacemark/country –