2015-09-23 35 views

回答

0

这是我的解决方案:

let geocoder = CLGeocoder() 
geocoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) in 

       if error != nil { 
        print("Error: \(error?.localizedDescription)") 
       } 

       if let myMarks = placemarks { 
        if let placemark = myMarks.last { 
         if let addressLine = (placemark.addressDictionary?["FormattedAddressLines"] as? [String]) { 
          self.addressLabel.text = addressLine.joined(separator: ", ") 
         } 
        } 
       } 
      }) 

厄尔尼诺键 “FormattedAddressLines” 这样的顺序返回一个数组:姓名,街道,城市,州,邮编,国家。如果您打印地址线,则会看到如下所示的内容:“Apple Inc.,1 Infinite Loop,Cupertino,CA 95014,United States”。