您好,我是 Xcode 和 Swift 的新手。
我正在编写一个应用程序,用户可以在其中从列表中选择一个国家,以便它向 map 添加图钉。
基本上,它只是一张带有图钉的 map 。
我在哪里可以获得默认国家/地区列表?比如下拉菜单之类的,这样我就不需要自己对所有国家/地区进行硬编码。
然后,我知道下一个问题很重要,所以我只希望得到一些指导:
有人可以告诉我如何使用所选国家/地区的 GPS 坐标以便在 map 上放置图钉吗?
谢谢大家的帮助。
最佳答案
试试这个。
func counrtyNames() -> NSArray{
var countryCodes = NSLocale.ISOCountryCodes()
var countries:NSMutableArray = NSMutableArray()
for countryCode in countryCodes{
let dictionary : NSDictionary = NSDictionary(object:countryCode, forKey:NSLocaleCountryCode)
//get identifire of the counrty
var identifier:NSString? = NSLocale.localeIdentifierFromComponents(dictionary as! [String : String])
let locale = NSLocale.currentLocale()
//get country name
let country = locale.displayNameForKey(NSLocaleCountryCode, value : countryCode)//replace "NSLocaleIdentifier" with "NSLocaleCountryCode" to get language name
if country != nil {//check the country name is not nil
countries.addObject(country!)
}
}
NSLog("\(countries)")
return countries
}
关于ios - swift 和 Xcode : How to have a default list of countries?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32584040/