我正在尝试提取CLPlacemark对象中返回的dependentLocality信息。数据(匿名)看起来像
{
"cache_control" = CACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
ttl = 15768000;
type = "COMPONENT_TYPE_ADDRESS";
value = (
{
address = {
"known_accuracy" = POINT;
"localized_address" = (
{
address = {
formattedAddressLine = (
"111 Some St",
"Brooklyn, NY 11111-1111",
"United States"
);
structuredAddress = {
administrativeArea = "New York";
administrativeAreaCode = NY;
areaOfInterest = (
"Long Island"
);
country = "United States";
countryCode = US;
dependentLocality = (
"Bedford Stuyvesant",
Brooklyn
);
fullThoroughfare = "111 Some St";
geoId = (
);
locality = "New York";
postCode = 11206;
postCodeExtension = 1111;
postCodeFull = "11111-1111";
subAdministrativeArea = Kings;
subLocality = Brooklyn;
subThoroughfare = 111;
thoroughfare = "Some St";
};
};
locale = "en_US";
}
);
};
}
);
"values_available" = 1;
version = 7;
"version_domain" = (
apple,
revgeo,
US
);
},
我无法访问内容(除了通过Apple的structuredAddress属性,它不包含我想要的内容)。我想提取" Bedford Stuyvesant",Brooklyn"例如,从上面的内容来看。已经尝试了很多方法,但是例如。将地标转换为NSDictionary失败。任何帮助将不胜感激!
答案 0 :(得分:0)
也许你可以做一些字符串处理来从你的placemark.description中提取dependentLocality。但是你为什么不只使用placemark.subLocality属性?
NSString *geoMapItem = placemark.description;
NSRange start = [geoMapItem rangeOfString:@"dependentLocality"];
NSRange end = [geoMapItem rangeOfString:@")" options:NSCaseInsensitiveSearch range:NSMakeRange(start.location, 1000)];
NSString *dataString = [geoMapItem substringWithRange:NSMakeRange(start.location, end.location - start.location + end.length)];
dataString = [dataString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
dataString = [dataString stringByReplacingOccurrencesOfString:@" " withString:@""];
dataString = [dataString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
start = [dataString rangeOfString:@"("];
end = [dataString rangeOfString:@")"];
NSString *arrayString = [dataString substringWithRange:NSMakeRange(start.location + 1, end.location - start.location - 1)];
NSArray *array = [arrayString componentsSeparatedByString:@","];