如何在ios中获取与位置搜索相关的图像

时间:2014-08-13 08:27:41

标签: ios mapkit

我正在根据地图搜索创建一个iPad MasterDetail应用程序 MasterViewController对关键字执行搜索,并将结果传递给TableViewDetailView,并提供包含MasterView中所选项目的地图。当我选择annotation时,我想在子视图中添加与搜索位置相关的图像。

1 个答案:

答案 0 :(得分:2)

以下是解决问题的方法。

NSString *nearBySearch = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=%f,%f&radius=200&key=%@",_mapItem.placemark.location.coordinate.latitude, _mapItem.placemark.location.coordinate.longitude, kGOOGLE_API_KEY];
NSURL *searchURL = [NSURL URLWithString:nearBySearch];    
NSData* data = [NSData dataWithContentsOfURL: searchURL];
NSDictionary* json = [NSJSONSerialization
                      JSONObjectWithData:data
                      options:kNilOptions
                      error:&error];
NSArray* placeResults = [json objectForKey:@"results"];
NSDictionary *place = [placeResults objectAtIndex:i];
NSArray *photos = [place objectForKey:@"photos"];    
NSArray *referencArray = [photoDetails objectForKey:@"photo_reference"];
NSString *photoURLString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/photo?maxwidth=300&maxheight=300&photoreference=%@&key=%@", [referenceArray objectAtIndex:i], kGOOGLE_API_KEY];
NSURL *photoURL = [NSURL URLWithString:photoURLString];
NSData *imageData = [NSData dataWithContentsOfURL:photoURL];
placeImage = [UIImage imageWithData:imageData];

感谢@Anil Prasad提供有价值的链接和帮助。