2017-12-03 123 views
-1

嘿我有一些座標[「37.7」,「-122.4」],我試圖用來反轉geoCode。所以我可以得到一個簡單的UI標籤的城市和國家。 但是,當我使用CLLocation通過用placeMark標準的administrativeArea var/method來獲取狀態時,它返回nil。ClLocation地標不返回管理區域

▿一些:1個元件 - 0:舊金山灣,舊金山灣,舊金山,美國@ < + 37.80000000,-122.50000000> +/-100.00米,區域CLCircularRegion(標識符:」 < + 37.79999999,-122.50000000>半徑141.72' ,中心:< + 37.79999999,-122.50000000>,半徑:141.72米)

這是我從完成處理回。這使得很明顯,沒有任何狀態從這個返回。爲什麼會這樣,我還能如何獲得這個狀態。

封閉的代碼塊控制這個行動所有幫助表示讚賞。

CLGeocoder().reverseGeocodeLocation(location, completionHandler: { (placeMark, error) in 
      if error != nil{ 
       print("There was an error") 
      }else{ 
       if let place = placeMark?[0]{ 
        print(place) 
        print(place.locality ?? "") 
        print(place.subAdministrativeArea ?? "") 
        let myAttribute = [NSAttributedStringKey.font:UIFont(name: "Times New Roman", size: 15.3)!] 
        let myAttrString = NSAttributedString(string: place.locality ?? "", attributes: myAttribute) 
        locLabel.attributedText = myAttrString 
       } 
      } 

     }) 

回答

0

您正在與在線數據庫進行交互。數據庫中的這個條目沒有狀態。這有點可以理解,因爲你似乎是在太平洋的一部分水體中;它不在一個國家的領土內。但是,無論是這個原因,還是數據庫中的一個怪癖或錯誤,對此你都無能爲力。你已經選擇使用這個數據庫,你必須接受它給你的東西。

+0

如果您覺得數據庫中存在錯誤,則可能會對Apple提出錯誤。 – matt

+0

是的,我剛剛意識到我身處水體 –