2015-09-23 41 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」。