我尝试从CLPlacemark对象获取 ISO国家代码区域设置,如“en_US”。当我在对象上执行NSLog时,我会收到很多文本,包括:
address = {
"localized_address" = (
{
address = {
formattedAddressLine = (
"Piccadilly Circus",
"Coventry Street",
London,
W1J,
England
);
structuredAddress = {
administrativeArea = England;
areaOfInterest = (
"Piccadilly Circus",
"Great Britain"
);
country = "United Kingdom";
countryCode = GB;
dependentLocality = (
Mayfair
);
fullThoroughfare = "Coventry Street";
geoId = (
);
locality = London;
postCode = W1J;
subAdministrativeArea = London;
subLocality = Mayfair;
thoroughfare = "Coventry Street";
};
};
locale = "en_US";
你可以在最后一行看到我需要的信息。但我不知道如何直接访问这些信息。
当我尝试访问CLPlacemark的ISOcountryCode属性时,我只获得GB。
感谢您的帮助 哈德
答案 0 :(得分:0)
有点hackish,但这是你可以获取信息的一种方式
NSString *placemarkDescription = [yourPlacemark description];
NSString *regex = @"(locale)(\\s+)(=)(\\s+)("".*?"")(;)";
NSRange localeRange = [placemarkDescription rangeOfString:regex options:NSRegularExpressionSearch];
NSString *locale = [placemarkDescription substringWithRange:localeRange];
正则表达式很丑陋,可能会有所改进(我使用http://txt2re.com),但这应该可以为你获取语言环境。