百度地图自定义marker

turboksiOS66

Simulator Screen Shot - iPhone 12 - 2021-08-05 at 18.38.36.png


#import "HomeViewController.h"

#import "PaopaoView.h"


@interface HomeViewController ()<BMKMapViewDelegate>

@property (nonatomic, strong) BMKMapView * mapView;

@end


@implementation HomeViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    self.navigationController.navigationBar.hidden = YES;

    

    _mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, DEVICE_HEIGHT)];

    _mapView.delegate = self;

    //设置地图显示比例。

    [_mapView setZoomLevel:20];

    //显示比例尺

    _mapView.showMapScaleBar = YES;

    //设置显示类型(0 空白 1 地图 2卫星)

    _mapView.mapType = 2;

    //设置显示楼层效果

    _mapView.buildingsEnabled = YES;

    

    //设置CLLocationCoordinate2D 位置

    CLLocationCoordinate2D location;

    location.latitude = 39.915111;

    location.longitude = 116.403945;

    _mapView.centerCoordinate = location;

    [self.view addSubview:_mapView];

    

    BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];

    annotation.coordinate = CLLocationCoordinate2DMake(39.915111, 116.403945);

    [_mapView addAnnotation:annotation];

    

}


#pragma mark - BMKMapViewDelegate

- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation

{

    if ([annotation isKindOfClass:[BMKPointAnnotation class]])

    {

        static NSString *reuseIndetifier = @"annotationReuseIndetifier";

        BMKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];

        if (annotationView == nil)

        {

            annotationView = [[BMKAnnotationView alloc] initWithAnnotation:annotation

                                                           reuseIdentifier:reuseIndetifier];

        }

        

        //        annotationView.image = [UIImage imageNamed:@""];

        [annotationView setSelected:YES];

        

        annotationView.canShowCallout = YES;

        PaopaoView *customPopView = [[PaopaoView alloc] init];

        customPopView.frame = CGRectMake(0, 0, 98, 84);

        customPopView.image = [UIImage imageNamed:@"ppima"];

        //        customPopView.title = @"北京";

        customPopView.subtitle = @"查看高清街景>>";

        customPopView.controller = self;

        

        BMKActionPaopaoView *pView = [[BMKActionPaopaoView alloc] initWithCustomView:customPopView];

        pView.frame = customPopView.frame;

        annotationView.paopaoView = pView;

        

        return annotationView;

    }

    return nil;

}


-(void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    self.navigationController.navigationBar.hidden = YES;

    [_mapView viewWillAppear];

}

-(void)viewWillDisappear:(BOOL)animated

{

    [super viewWillDisappear:animated];

    self.navigationController.navigationBar.hidden = NO;

    [_mapView viewWillDisappear];

}


@end



PaopaoView


#import <UIKit/UIKit.h>


@interface PaopaoView : UIView

@property (nonatomic, strong) UIImage *image;

@property (nonatomic, strong) NSString *subtitle;

@property (nonatomic, strong) UIViewController *controller;

@end




#import "PaopaoView.h"


@interface PaopaoView ()

@property (nonatomic, strong) UIImageView   *backView;

@property (nonatomic, strong) UIImageView   *portraitView;

@property (nonatomic, strong) UILabel       *subtitleLabel;

@end

@implementation PaopaoView


#pragma mark - draw rect


- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        [self initSubViews];

    }

    return self;

}


- (void)initSubViews

{

    // 添加背景图片

    self.backView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 98, 84)];

    self.backView.image = [UIImage imageNamed:@"ppback"];

    [self addSubview:self.backView];

    

    // 添加图片

    self.portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 88, 49)];

    self.portraitView.backgroundColor = [UIColor blackColor];

    [self addSubview:self.portraitView];

    

    // 添加标题

    self.subtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 54, 98, 20)];

    self.subtitleLabel.textColor = [UIColor whiteColor];

    self.subtitleLabel.text = self.subtitle;

    self.subtitleLabel.font = smallFontStyle;

    self.subtitleLabel.textAlignment = NSTextAlignmentCenter;

    [self addSubview:self.subtitleLabel];

}


- (void)setSubtitle:(NSString *)subtitle

{

    self.subtitleLabel.text = subtitle;

}


- (void)setImage:(UIImage *)image

{

    self.portraitView.image = image;

}

@end












标签: 地图

相关文章

WKWebView

WKWebView

<!DOCTYPE html><head>    <title>HTML</title>    <meta...

iOS 之导航渐变,并且跳转返回保持滑动状态

iOS 之导航渐变,并且跳转返回保持滑动状态

导航刚开始进入为透明,根据我们的滑动确定要显示的背景色。先看一下效果图:一:创建demo,将3个界面添加到控制器中,此过程比较简单代码就不上了。二:在第一页的viewDidload中将当前页面的导航设...

RunLoop

RunLoop

RunLoop一、基础理论顾名思义1.    运行循环2.    在程序运行过程中循环做一些事情3.    是用户态和内核态之间的交互模式应...

Runtime详解

Runtime详解

The Objective-C language defers as many decisions as it can from compile time and link time to runti...

iOS程序的内存布局

iOS程序的内存布局

    代码段:编译之后的代码    数据段:字符串常量:比如NSString * str = @“123”已初始化数据:已初始化的全局变量...

OC对象的本质

OC对象的本质

我们平时编写的oc代码、底层实现其实是C\C++代码OC代码    ——>    C\C++    ——>  &nbs...