效果图:
首先导入道德地图的SDK,导入步骤不在这里介绍
2:包含头文件:
- #import <AMapSearchKit/AMapSearchAPI.h>
- @property(nonatomic,strong)AMapSearchAPI *mapSearch;
- @property(nonatomic,strong)AMapPlaceSearchRequest *poiRequest;
- -(void)searchAroundLocal:(AMapGeoPoint *)geoPoint
- {
- if ( !self.mapSearch) {
- self.mapSearch=[[AMapSearchAPI alloc] initWithSearchKey:(NSString *)APIKey Delegate:self];
- }
- self.poiRequest = [[AMapPlaceSearchRequest alloc] init];
- AMapGeoPoint *searchPoint =[AMapGeoPoint locationWithLatitude:
- 22.540000
- longitude:113.900000];
- self.poiRequest.searchType = AMapSearchType_PlaceAround;//搜索的类型为周边搜索
- // self.poiRequest.types =AMapRequireGroupbuy; //搜索的内容
- self.poiRequest.offset = 120; //每页搜索的信息个数
- self.poiRequest.location = searchPoint; //搜索的中心点
- self.poiRequest.keywords=searchKeyString;
- self.poiRequest.radius = 5000; //搜索半径
- self.poiRequest.sortrule = 0; //结果以远近排序
- //发起POI搜索
- [self.mapSearch AMapPlaceSearch:self.poiRequest];//发起请求搜索
- }
- #pragma mark - AMapSearchDelegate
- /* POI 搜索回调. */
- - (void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSearchResponse *)response
- {
- NSLog(@"inset=%@",TABLEHEAD);
- for (AMapPOI *p in response.pois) {
- if (p) {
- [locArr addObject:p];
- }
- }
- [locArr insertObject:TABLEHEAD atIndex:0];
- [self.view endEditing:YES];
- [self.tableView reloadData];
- }
- - (void)searchRequest:(id)request didFailWithError:(NSError *)error
- {
- NSLog(@"====出错信息:%@",error);
- }
- - (void)search:(id)searchRequest error:(NSString *)errInfo __attribute__ ((deprecated("use -search:didFailWithError instead.")))
- {
- NSLog(@"====出错信息:%@",errInfo);
- }
其中
self.poiRequest.keywords=searchKeyString;