How to obtain country, state, city from reverseGeocodeCoordinate?

前端 未结 4 1287
无人及你
无人及你 2020-12-07 21:26

GMSReverseGeocodeResponse contains

- (GMSReverseGeocodeResult *)firstResult;

whose definition is like:

@interf         


        
4条回答
  •  渐次进展
    2020-12-07 21:59

    In swift 4.0 the func gets CLLocation and return postal address

      func geocodeCoordinates(location : CLLocation)->String{
             var postalAddress  = ""
            let geocoder = GMSGeocoder()
            geocoder.reverseGeocodeCoordinate(location.coordinate, completionHandler: {response,error in
                if let gmsAddress = response!.firstResult(){
                    for line in  gmsAddress.lines! {
                        postalAddress += line + " "
                    }
                   return postalAddress
                }
            })
            return ""
        }
    

提交回复
热议问题