转自:http://m.blog.csdn.net/blog/donhao/7695480
前文中的POI搜索可以在指定地点周围特定范围内搜索POI,假设用户想要在上海市人民广场搜索“北京”,那么POI返回的结果可能是附近的北京烤鸭店POI列表。为此,有时我们需要区分用户输入的搜索内容是否是一个地址,这里便需要用到本文将要阐述的地址搜索。
1. 首先进行搜索
BMKSearch* search = [[BMKSearch alloc] init]; //创建搜索对象
search.delegate = self; //代理设置为自身,搜索之后会自动回调下一步中的函数
[search geocode:"北京" withCity:@""]; //搜索北京
//[search release];//注意,这里不能release,否则无法搜索。应该将search定义为成员变量
2. 处理搜索结果
- (void)onGetAddrResult:(BMKAddrInfo*)result errorCode:(int)error
{
if (error == BMKErrorOk) {
BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init];
item.coordinate = result.geoPt;
item.title = result.strAddr;
[mapView addAnnotation:item];
[item release];
}
}
上边会自动回调,将搜索到的POI在地图上通过Annotation显示出来。
iOS基于百度地图的开发(6)——google坐标转换成百度坐标
iOS基于百度地图的开发(7)——百度坐标转换成Google坐标