正好做到百度地图的poi检索,拿来分享一下,基于百度地图2.3.0SDK开发,说实话,这个新版本poi真不好用
先来看头文件里面,定义poi对象,当然你也可以写到实现文件里面
1
2
3
4
5
6
7
|
#import
#import "BMapKit.h"
@interface NearByPlaceViewController : ViewControllerBase
{
BMKPoiSearch *_poiSearch;
//poi搜索
}
@end
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#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
|