我正在开发应用程序,我正在使用谷歌地方选择器API获取地址.
placePicker.pickPlaceWithCallback { (place: GMSPlace?, error: NSError?) -> Void in if let error = error { print("Error occurred: \(error.localizedDescription)") return } // 3 if let place = place { let coordinates = CLLocationCoordinate2DMake(place.coordinate.latitude, place.coordinate.longitude) let marker = GMSMarker(position: coordinates) marker.title = place.name marker.map = self.googleMapView self.googleMapView.animateToLocation(coordinates) self.delegate?.userAddress(place.formattedAddress! ) self.navigationController!.popViewControllerAnimated(true) } else { Print(@"Place name %@", place.name); Print(@"Place address %@", place.formattedAddress); Print(@"Place placeID %@", place.placeID); Print(@"Place attributions %@", place.attributions); } }
在这里,我正在获得包括国家,州和城市在内的完整地址.
我想将国家和城市与我没有找到任何解决方案的地址分开.
任何帮助,将不胜感激.
请检查以下代码,以便在swift中的google place picker api中显示单独的国家/地区.它对我有用!!!
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..