How to get the Images related to a Location search in ios

白昼怎懂夜的黑 提交于 2019-12-11 09:36:24

问题


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.


回答1:


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];

Thanks @Anil Prasad for giving valuable link and help.



来源:https://stackoverflow.com/questions/25281442/how-to-get-the-images-related-to-a-location-search-in-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!