分篇介紹最新百度地圖相關應用
一识脆、環(huán)境配置:
http://www.reibang.com/p/be592ed98ebf
二析恢、顯示與定位:
http://www.reibang.com/p/154c7840ffa5
三剔氏、根據(jù)經(jīng)緯度描點:
http://www.reibang.com/p/a4065c3f0457
四、大頭針與氣泡:
http://www.reibang.com/p/bb8f8f3c1ef1
五成洗、給大頭針加tag值:
http://www.reibang.com/p/6023465da2e7
六印机、問題處理:
http://www.reibang.com/p/c8b1449efea7
本篇介紹大頭針與氣泡!
項目demo: https://github.com/Dongxk/XKBMKMap.git
效果:
1鞭衩、修改大頭針屬性
#pragma mark --- BMKMapViewDelegate
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation{
//對大頭針以及氣泡進行一些設置
if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
static NSString *identifier = @"BMKAnnotationView";
BMKAnnotationView *annotationView = [[BMKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
//修改大頭針圖片
annotationView.image = [UIImage imageNamed:@"location"];
//是否允許點擊
annotationView.canShowCallout = YES;
// 等一些其他屬性設置
///.....
return annotationView;
}
return nil;
}
2学搜、 點擊大頭針
#pragma mark --- 點擊大頭針事件
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view{
//[mapView deselectAnnotation:view.annotation animated:NO];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"您點擊了大頭針" delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alert show];
}
3、 點擊氣泡:
在此方法中可以獲取到點擊了大頭針以及泡泡對應的信息:
/// 要顯示的標題论衍;注意:如果不設置title,無法點擊annotation,也無法使用回調(diào)函數(shù)瑞佩;
@property (copy) NSString *title;
/// 要顯示的副標題
@property (copy) NSString *subtitle;
但是如果對應一個接口返回的json數(shù)據(jù),如果要回去點擊了某條數(shù)據(jù)對應的id呢饲齐,該怎么辦钉凌?怎么給大頭針加唯一的標識?
百度地圖不支持直接添加tag值捂人。 所以這里自定義了一個大頭針賦值方法御雕,如你也有此需求,請看下一篇滥搭。
#pragma mark --- 點擊氣泡事件
- (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"您點擊了泡泡" delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alert show];
}