当前位置:  开发笔记 > IOS > 正文

如何在swift中的google place picker api中将国家/地区与地址分开

如何解决《如何在swift中的googleplacepickerapi中将国家/地区与地址分开》经验,为你挑选了1个好方法。

我正在开发应用程序,我正在使用谷歌地方选择器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);
            }
        }

在这里,我正在获得包括国家,州和城市在内的完整地址.

我想将国家和城市与我没有找到任何解决方案的地址分开.

任何帮助,将不胜感激.



1> 小智..:

请检查以下代码,以便在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..

推荐阅读
jerry613
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有