美文网首页编码里程iOS Coding地图定位
iOS 百度地图 添加大头针(Annotation)

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

作者: Bug集 | 来源:发表于2015-11-01 14:40 被阅读2665次

    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其代理方法一同写上即可.

    相关文章

      网友评论

      • 6a72763a8974:我想让百度地图那个我的位置的系统蓝色大头针消失怎么做呢

      本文标题:iOS 百度地图 添加大头针(Annotation)

      本文链接:https://www.haomeiwen.com/subject/bgqqhttx.html