标签:color os io 文件 for ar 问题 cti
正好做到百度地图的poi检索,拿来分享一下,基于百度地图2.3.0SDK开发,说实话,这个新版本poi真不好用
先来看头文件里面,定义poi对象,当然你也可以写到实现文件里面
#import <UIKit/UIKit.h> #import "BMapKit.h" @interface NearByPlaceViewController : ViewControllerBase <BMKPoiSearchDelegate> { BMKPoiSearch *_poiSearch; //poi搜索 } @end
#import "NearByPlaceViewController.h" #import "UserLocationManager.h" #import "iToast.h" @interface NearByPlaceViewController () { NSString *_cityName; // 检索城市名 NSString *_keyWord; // 检索关键字 int currentPage; // 当前页 } @property (retain,nonatomic) NSMutableArray *poiResultArray; //poi结果信息集合 @end @implementation NearByPlaceViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; [self setArraySpace]; [self initPoiSearch]; } #pragma mark --对数组开空间 -(void)setArraySpace { NSMutableArray *mutArr1 = [[NSMutableArray alloc]init]; _poiResultArray = mutArr1; NSMutableArray *mutArr2 = [[NSMutableArray alloc]init]; _searchHistoryArray = mutArr2; } #pragma mark --初始化poi类 -(void)initPoiSearch { _poiSearch = [[BMKPoiSearch alloc]init]; _poiSearch.delegate = self; currentPage = 0; //附近云检索,其他检索方式见详细api BMKNearbySearchOption *nearBySearchOption = [[BMKNearbySearchOption alloc]init]; nearBySearchOption.pageIndex = currentPage; //第几页 nearBySearchOption.pageCapacity = 10; //最多几页 nearBySearchOption.keyword = @"设施"; //检索关键字 nearBySearchOption.location = [UserLocationManager sharedInstance].clloction.coordinate; // poi检索点 nearBySearchOption.radius = 1000; //检索范围 m BOOL flag = [_poiSearch poiSearchNearBy:nearBySearchOption]; if(flag) { NSLog(@"城市内检索发送成功"); } else { NSLog(@"城市内检索发送失败"); } } #pragma mark --BMKPoiSearchDelegate /** *返回POI搜索结果 *@param searcher 搜索对象 *@param poiResult 搜索结果列表 *@param errorCode 错误号,@see BMKSearchErrorCode */ - (void)onGetPoiResult:(BMKPoiSearch*)searcher result:(BMKPoiResult*)poiResult errorCode:(BMKSearchErrorCode)errorCode { if (errorCode == BMK_SEARCH_NO_ERROR) { for (int i = 0; i < poiResult.poiInfoList.count; i++) { BMKPoiInfo* poi = [poiResult.poiInfoList objectAtIndex:i]; [_poiResultArray addObject:poi]; } } else if (errorCode == BMK_SEARCH_RESULT_NOT_FOUND) { [self setToast:iToastGravityBottom withText:@"抱歉,查不到你附近范围内的信息!"]; } } #pragma mark - toast -(void)setToast:(iToastGravity) gravity withText:(NSString*) text { iToast *toast = [iToast makeText:text]; [toast setGravity:gravity]; [toast setDuration:5]; [toast setFontSize:15]; [toast show]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
大家有什么不明白的可以给我留言,必回,彼此交流一下,后续我会把做到的百度地图遇到的问题详细记录,大家可以多交流一下!
iOS百度地图poi检索(基于百度地图2.3.0SDK开发),布布扣,bubuko.com
iOS百度地图poi检索(基于百度地图2.3.0SDK开发)
标签:color os io 文件 for ar 问题 cti
原文地址:http://my.oschina.net/u/1025290/blog/305383