我正在使用MapKit进行本地搜索,返回一个或多个MKMapItem对象。但是我可以在调试器中看到对象的成员但我无法访问。我特别需要的是UID。
我已尝试过item.placemark,但它不允许我访问UID。这看起来应该非常简单。我在这里缺少什么?
这不起作用: NSString * uid = item.placemark.UID
这不起作用:
NSDictionary *mapItemDictionary = (NSDictionary *)item;
NSString *uid = [mapItemDictionary objectForKey:@"UID"];
但是调试器命令po项显示了对象的所有成员:
Name: Shell CurrentLocation: 0 Place: <GEOPlace: 0x17014e650>
{
address = {
business = (
{
**UID = 2478578482074921045**;
URL = "www.shell.com";
canBeCorrectedByBusinessOwner = 1;
name = Shell;
source = (
{
"source_id" = A3H0281540;
"source_name" = "acxiom_us";
},
{
"source_id" = 2276257;
"source_name" = localeze;
}
);
telephone = "+14803968213";
}
);
任何有关此的帮助将不胜感激。这是我正在使用的代码:
MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:request];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error)
{
[response.mapItems enumerateObjectsUsingBlock:^(MKMapItem *item, NSUInteger idx, BOOL *stop)
{
MKPlacemark *placemark = (MKPlacemark *)item.placemark;
NSDictionary *addressDict = placemark.addressDictionary;
NSArray *businessArray = addressDict[@"business"];// businessArray is NIL
NSString *uid=nil;
if (businessArray != nil && businessArray.count >0) {
NSDictionary *businessDict=businessArray[0];
uid=businessDict[@"UID"];
}
NSLog(@"UID is %@",uid);
}];
答案 0 :(得分:1)
好的,经过大量的挖掘后,似乎信息出现在几个私人对象中。 “place”属性是GEOPlace,它有一个属性business,它是一个包含GEOBusiness对象的数组。由于这是私有数据,因此无法通过属性直接访问它,但您可以通过键值编码获取它。以下代码提取UID -
[response.mapItems enumerateObjectsUsingBlock:^(MKMapItem *item, NSUInteger idx, BOOL *stop) {
NSValue *place = [item valueForKey:@"place"];
NSArray *businessArray = (NSArray *)[place valueForKey:@"business"];
NSNumber *uid=nil;
if (businessArray != nil && businessArray.count >0) {
id geobusiness=businessArray[0];
uid=[geobusiness valueForKey:@"uID"];
}
NSLog(@"UID is %@",[uid stringValue]);
}];
由于这是私有数据结构,因此无法保证它不会发生变化。我也不确定App商店验证过程是否会将此标记为私有API访问 - 因为它使用valueForKey
我不认为它会,但是没有保证。