标签:
// // PoiViewController.m // baiDuDemo // // Created by City--Online on 15/6/4. // Copyright (c) 2015年 XQB. All rights reserved. // #import "PoiViewController.h" #import "BMKTypes.h" #import "BMKPoiSearch.h" #import "BMKBusLineSearch.h" #import "BMKGeocodeSearch.h" @interface PoiViewController ()<BMKPoiSearchDelegate,BMKGeoCodeSearchDelegate,UITableViewDataSource,UITableViewDelegate> //周边、详情搜索 @property(nonatomic,strong) BMKPoiSearch *searcher; //周边搜索条件 @property(nonatomic,strong) BMKNearbySearchOption *nearbySearchOption; //详情搜索条件 @property(nonatomic,strong) BMKPoiDetailSearchOption *detailSearchOption; @property(nonatomic,strong) UITableView *tableView; //周边搜索列表数据 @property(nonatomic,strong) NSMutableArray *poiInfoList; //地理信息编码 @property(nonatomic,strong) BMKGeoCodeSearch *geoCodeSearch; @end @implementation PoiViewController - (void)viewDidLoad { [super viewDidLoad]; //初始化检索对象 _searcher =[[BMKPoiSearch alloc]init]; _searcher.delegate = self; //发起周边检索 _nearbySearchOption = [[BMKNearbySearchOption alloc]init]; // _nearbySearchOption.pageIndex = 1; // _nearbySearchOption.pageCapacity = 10; _nearbySearchOption.location=CLLocationCoordinate2DMake(22.5538, 114.0672); _nearbySearchOption.radius=5000; _nearbySearchOption.sortType=BMK_POI_SORT_BY_DISTANCE; _nearbySearchOption.keyword = @"小吃"; BOOL flag = [_searcher poiSearchNearBy:_nearbySearchOption]; if(flag) { NSLog(@"周边检索发送成功"); } else { NSLog(@"周边检索发送失败"); } // 地理信息编码 _geoCodeSearch =[[BMKGeoCodeSearch alloc]init]; _geoCodeSearch.delegate = self; BMKGeoCodeSearchOption *geoCodeSearchOption = [[BMKGeoCodeSearchOption alloc]init]; geoCodeSearchOption.city= @"深圳市"; geoCodeSearchOption.address = @"音乐厅"; flag = [_geoCodeSearch geoCode:geoCodeSearchOption]; if(flag) { NSLog(@"geo检索发送成功"); } else { NSLog(@"geo检索发送失败"); } // 地理信息反编码 CLLocationCoordinate2D pt = (CLLocationCoordinate2D){22.588393, 113.946523}; BMKReverseGeoCodeOption *reverseGeoCodeSearchOption = [[ BMKReverseGeoCodeOption alloc]init]; reverseGeoCodeSearchOption.reverseGeoPoint = pt; flag = [_geoCodeSearch reverseGeoCode:reverseGeoCodeSearchOption]; if(flag) { NSLog(@"反geo检索发送成功"); } else { NSLog(@"反geo检索发送失败"); } _tableView =[[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain]; [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"]; _tableView.dataSource=self; _tableView.delegate=self; [self.view addSubview:_tableView]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _poiInfoList.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; BMKPoiInfo *poiInfo=[_poiInfoList objectAtIndex:indexPath.row]; cell.textLabel.text=[NSString stringWithFormat:@"%@ %@",poiInfo.name,poiInfo.uid]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //发起详情搜索 _detailSearchOption=[[BMKPoiDetailSearchOption alloc]init]; BMKPoiInfo *poiInfo=[_poiInfoList objectAtIndex:indexPath.row]; _detailSearchOption.poiUid=poiInfo.uid; BOOL flag = [_searcher poiDetailSearch:_detailSearchOption]; if(flag) { NSLog(@"详情检索发起成功"); //详情检索发起成功 } else { NSLog(@"详情检索发送失败"); //详情检索发送失败 } } //周边搜索 - (void)onGetPoiResult:(BMKPoiSearch*)searcher result:(BMKPoiResult*)poiResult errorCode:(BMKSearchErrorCode)errorCode { if (errorCode == BMK_SEARCH_NO_ERROR) { _poiInfoList=[poiResult.poiInfoList mutableCopy]; [_tableView reloadData]; NSLog(@"%d %d %d %d",poiResult.totalPoiNum,poiResult.currPoiNum,poiResult.pageNum,poiResult.pageIndex); for (BMKPoiInfo *poiInfo in poiResult.poiInfoList) { NSLog(@"name:%@ UId:%@",poiInfo.name,poiInfo.uid); } for (BMKCityListInfo *CityListInfo in poiResult.cityList) { NSLog(@"%@",CityListInfo.city); } } else if (errorCode == BMK_SEARCH_AMBIGUOUS_KEYWORD){ //当在设置城市未找到结果,但在其他城市找到结果时,回调建议检索城市列表 // result.cityList; NSLog(@"起始点有歧义"); } else { NSLog(@"抱歉,未找到结果"); } } //详情搜索 - (void)onGetPoiDetailResult:(BMKPoiSearch*)searcher result:(BMKPoiDetailResult*)poiDetailResult errorCode:(BMKSearchErrorCode)errorCode { if (errorCode == BMK_SEARCH_NO_ERROR) { NSLog(@"%@ %@ %@ %@",poiDetailResult.name,poiDetailResult.address,poiDetailResult.phone,poiDetailResult.shopHours); NSString *message=[NSString stringWithFormat:@"店名:%@ \n地址:%@\n 电话:%@\n 营业时间:%@\n经纬度:%lf %lf",poiDetailResult.name,poiDetailResult.address,poiDetailResult.phone,poiDetailResult.shopHours,poiDetailResult.pt.latitude,poiDetailResult.pt.longitude]; UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"搜索详情" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } else if (errorCode == BMK_SEARCH_AMBIGUOUS_KEYWORD){ //当在设置城市未找到结果,但在其他城市找到结果时,回调建议检索城市列表 // result.cityList; NSLog(@"起始点有歧义"); } else { NSLog(@"抱歉,未找到结果"); } } - (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error { if (error == BMK_SEARCH_NO_ERROR) { NSLog(@"%lf %lf %@",result.location.latitude,result.location.longitude,result.address); } else { NSLog(@"抱歉,未找到结果"); } } - (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error { if (error == BMK_SEARCH_NO_ERROR) { NSLog(@"%@",result.address); for (BMKPoiInfo *poiInfo in result.poiList) { NSLog(@"%@ %@",poiInfo.name,poiInfo.address); } } else { NSLog(@"抱歉,未找到结果"); } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any_ resources that can be recreated. } @end
标签:
原文地址:http://www.cnblogs.com/cuiyw/p/4551501.html