O 需求
将指定经纬度,显示在百度地图上。
一 准备
详见《01 如何将百度地图加入IOS应用程序?》
二 编码
(New标示本次新添加的代码;Delete表示本次需要删除的代码;Modify表示本次被修改的代码)
1、在ViewController.mm中修改代码如下
- (void)viewDidLoad
{
……
// 添加一个PointAnnotation
BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
CLLocationCoordinate2D coor;
coor.latitude = 39.915;
coor.longitude = 116.404;
annotation.coordinate = coor;
annotation.title = @"test";
annotation.subtitle = @"this is a test!";
[mapView addAnnotation:annotation];
……
}
#pragma mark - 实现 BMKMapViewDelegate 中的方法
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
BMKPinAnnotationView *newAnnotation = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
newAnnotation.pinColor = BMKPinAnnotationColorPurple;
newAnnotation.animatesDrop = YES;
newAnnotation.draggable = YES;
return newAnnotation;
}
return nil;
}
执行后,效果如下:
三 下载 ......去下载源代码咯 ......
四 调试
五 思路
六 分析
七 疑问
1、实现的委托方法暂时不知道是干什么用的?