03 在百度地图上定位到指定位置

O 需求

将指定经纬度,显示在百度地图上。

一 准备

详见《01 如何将百度地图加入IOS应用程序?》

二 编码

(New标示本次新添加的代码;Delete表示本次需要删除的代码;Modify表示本次被修改的代码)

1、在ViewController.mm中修改代码如下

 1 - (void)viewDidLoad
 2 {
 3     ……
 4    // 添加一个PointAnnotation
 5     BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
 6     CLLocationCoordinate2D coor;
 7     coor.latitude = 39.915;
 8     coor.longitude = 116.404;
 9     annotation.coordinate = coor;
10     annotation.title = @"test";
11     annotation.subtitle = @"this is a test!";
12     [mapView addAnnotation:annotation];
13   ……
14 }
15 #pragma mark -  实现 BMKMapViewDelegate 中的方法 
16 - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
17 {
18     if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
19         BMKPinAnnotationView *newAnnotation = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];   
20         newAnnotation.pinColor = BMKPinAnnotationColorPurple;   
21         newAnnotation.animatesDrop = YES;
22         newAnnotation.draggable = YES;
23         
24         return newAnnotation;   
25     }
26     return nil;
27 }

执行后,效果如下:

三 下载   ......去下载源代码咯 ......

四 调试

五 思路

六 分析

七 疑问

1、实现的委托方法暂时不知道是干什么用的?

原文地址:https://www.cnblogs.com/ygm900/p/2783148.html