添加大頭針
_annotationView= [[BMKAnnotationViewalloc]init];
_annotation= [[BMKPointAnnotationalloc]init];
CLLocationCoordinate2Dcoor;//設(shè)置經(jīng)緯度
coor.latitude= [[_car_infoobjectForKey:@"msg_lat"]doubleValue];//經(jīng)度 ?float
coor.longitude= [[_car_infoobjectForKey:@"msg_lon"]doubleValue];//緯度
BMKCoordinateRegionregion;
region.center= coor;把你的經(jīng)緯度設(shè)置為中心點(diǎn)
_annotation.coordinate= coor;
[_mapViewaddAnnotation:_annotation];
//這是一句關(guān)鍵的代碼可以讓你的地圖跟著標(biāo)注點(diǎn)走
[_mapView setRegion:region animated:YES];
//這句代碼是添加標(biāo)注就顯示標(biāo)準(zhǔn)的內(nèi)容
[_mapView selectAnnotation:_annotationanimated:YES];就是顯示你的大頭針
自定義大頭針
- (BMKAnnotationView*)mapView:(BMKMapView*)mapView viewForAnnotation:(id)annotation{\
if(annotation ==_startPoint) {如果大頭針是你想改變那個(gè)
初始化并返回一個(gè)annotation view
@param annotation關(guān)聯(lián)的annotation對(duì)象
@param reuseIdentifier如果要重用view,傳入一個(gè)字符串,否則設(shè)為nil,建議重用view
@return初始化成功則返回annotation view,否則返回nil
BMKPinAnnotationView *annotationView = [[BMKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
annotationView.image= [UIImage imageNamed:@"hha"];設(shè)置大頭針氣泡圖片
從天上掉下效果annotationView.animatesDrop = YES;
annotationView.draggable=NO;是否可拖拽
returnannotationView;
}
}
待續(xù)。。。。