iOS百度地图poi检索(基于百度地图2.3.0SDK开发)
程序员文章站
2022-06-10 13:14:22
...
正好做到百度地图的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"
@interface NearByPlaceViewController ()
{
NSString *_cityName; // 检索城市名
NSString *_keyWord; // 检索关键字
int currentPage; // 当前页
}
@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 initPoiSearch];
}
#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];
BMKPoiInfo就是检索出来的poi信息
}
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
大家有什么不明白的可以给我留言,必回,彼此交流一下,后续我会把做到的百度地图遇到的问题详细记录,大家可以多交流一下!
转载于:https://my.oschina.net/u/1025290/blog/305383