2017-05-20 232 views
1

我有三个字段需要用户输入数据。第一个领域是选择一个国家,第二个领域是选择一个州/省,第三个领域是选择一个城市。国家城市州名单

是否有任何API为用户提供选择国家和基于该选择的功能,然后选择一个状态并根据该选择,然后为选定状态选择一个城市?

感谢

+0

复制方式: http://stackoverflow.com/questions/16571365/api-to-call-countries-and-states – sulabh

+0

[列表城市按国家(的可能的复制http://stackoverflow.com/questions/1794833 /按城市分类的城市列表) – Luzo

回答

1
  • 下载从here
  • 数据格式世界城市文本文件是City , Country , State , GeoID

现在你可以使用下面这段代码...

let text = try! String(contentsOfFile: Bundle.main.path(forResource: "world-cities", ofType: "txt")!) // Reading File 
let lineArray = text.components(separatedBy: "\n") // Separating Lines 

     for eachLA in lineArray 
     { 
      let wordArray = eachLA.components(separatedBy: ",") 
      // wordArray[0] is city , [1] is country and so on 
     } 

(这是一个盲目和快速的编码,原谅我的局限性)

+0

谢谢这有助于 –

相关问题