本文介绍了如何在iOS中获取与位置搜索相关的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在基于地图搜索创建iPad MasterDetail
应用程序.MasterViewController
对关键字执行搜索,然后将结果传递给TableView
和DetailView
,并提供一个映射,其中包含从MasterView
中选择的项.选择annotation
时,我想在子视图中添加与搜索位置相关的图像.
I am creating an iPad MasterDetail
application based on map search.MasterViewController
performs a search on the keyword and passes results to the TableView
and DetailView
and provides a map with the selected item from the MasterView
. I want to add the images related to the searched location in a subview when I select the annotation
.
推荐答案
这是我解决问题的方法.
Here is the way that I,ve solved the problem.
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提供有价值的链接和帮助.
Thanks @Anil Prasad for giving valuable link and help.
这篇关于如何在iOS中获取与位置搜索相关的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!