随手写一个DEMO:
- (void)viewDidLoad
{
[super viewDidLoad];
_search = [[BMKSearch alloc]init];
_search.delegate = self;
// 设置地图级别
[_mapView setZoomLevel:13];
_mapView.isSelectedAnnotationViewFront = YES;
//发起POI检索
BOOL flag = [_search poiSearchInCity:@"武汉" withKey:@"武汉协和医院" pageIndex:0];
if(flag){
NSLog(@"success!");
}else{
NSLog(@"error!");
}
}
- (void)onGetPoiResult:(NSArray*)poiResultList searchType:(int)type errorCode:(int)error
{
// 清楚屏幕中所有的annotation
NSArray* array = [NSArray arrayWithArray:_mapView.annotations];
[_mapView removeAnnotations:array];
BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init];
// 30.5907940162,114.2823383453
CLLocationCoordinate2D coor;
coor.latitude = 30.5907940162;
coor.longitude = 114.2823383453;
item.coordinate = coor;
item.title = @"武汉协和医院";
[_mapView addAnnotation:item];
_mapView.centerCoordinate = coor;
}
/**
*根据anntation生成对应的View
*@param mapView 地图View
*@param annotation 指定的标注
*@return 生成的标注View
*/
- (BMKAnnotationView *)mapView:(BMKMapView *)view viewForAnnotation:(id )annotation
{
// 生成重用标示identifier
NSString *AnnotationViewID = @"xieheMark";
// 检查是否有重用的缓存
BMKAnnotationView* annotationView = [view dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
// 缓存没有命中,自己构造一个,一般首次添加annotation代码会运行到此处
if (annotationView == nil) {
annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
((BMKPinAnnotationView*)annotationView).pinColor = BMKPinAnnotationColorRed;
// 设置重天上掉下的效果(annotation)
((BMKPinAnnotationView*)annotationView).animatesDrop = YES;
}
// 设置位置
annotationView.centerOffset = CGPointMake(0, -(annotationView.frame.size.height * 0.5));
annotationView.annotation = annotation;
// 单击弹出泡泡,弹出泡泡前提annotation必须实现title属性
annotationView.canShowCallout = YES;
// 设置是否可以拖拽
annotationView.draggable = NO;
return annotationView;
}