iOS 百度地图 添加大头针(Annotation)

http://potter528.bj.bdysite.com
1.首先根据百度开发者文档将环境和各种系统FrameWork导入

先创建一个mapview(BMKMapView)

然后在viewController中的viewDidAppear方法中添加Annotation

如果想改变大头针的颜色和形状,可以实现其代理方法

- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
        newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
        return newAnnotationView;
    }
    return nil;
}

从现在开始就一步一步就你做
1.实现mapview有几种方式
1.1第一种:IBOutlet BMKMapView *mapView;(与storyboard中相应的view进行关联)
1.2第二种:设置成属性,并在viewDidLoad中初始化
1.3第三种:设置成成员变量的方式,同上

2.在ViewController中重写viewDidAppear方法

 BMKPointAnnotation *point1 = [[BMKPointAnnotation alloc]init];
    
    point1.coordinate = CLLocationCoordinate2DMake(39, 116);
    
    point1.title = @"北京";
    
    [mapView addAnnotation:point1];

2.1其代理方法一同写上即可.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容