美文网首页iOS DeveloperiOS 开发每天分享优质文章
百度地图SDK学习——2.0 基本内容显示

百度地图SDK学习——2.0 基本内容显示

作者: playman | 来源:发表于2016-08-28 17:01 被阅读0次

    这次写的是,对于百度地图显示内容的基本认识。基本就是按照官方文档学习的,话不多说,开始看代码。

      本文是根据1.0内容接着写的
    

    布局

    布局

    地图类型

    类型有三种

    BMKMapTypeNone = 0, ///< 空白地图
    BMKMapTypeStandard = 1, ///< 标准地图
    BMKMapTypeSatellite = 2, ///< 卫星地图

    空白地图
    空白地图
    标准地图(默认)
    默认地图
    卫星地图
    卫星地图
    • 调用的方法是

    当前地图类型,可设定为标准地图、卫星地图
    @property (nonatomic) BMKMapType mapType;
    _mapView.mapType = 地图类型;

    交通状况

    打开交通状况

    打开交通状况

    关闭交通状况

    关闭交通状况

    调用的方法

    设定地图是否打开路况图层
    @property(nonatomic, getter=isTrafficEnabled) BOOL trafficEnabled;
    [_mapView setTrafficEnabled:YES/NO];

    城市热力图

    打开热力图

    打开热力图

    关闭热力图

    关闭热力图

    调用的方法

    设定地图是否打开百度城市热力图图层(百度自有数据),注:地图层级大于11时,可显示热力图
    @property(nonatomic, getter=isBaiduHeatMapEnabled) BOOL baiduHeatMapEnabled;
    [_mapView setBaiduHeatMapEnabled:YES/NO];

    代码奉上

    #import "ViewController.h"
    #import <BaiduMapAPI_Map/BMKMapView.h>
    #import <BaiduMapAPI_Base/BMKBaseComponent.h>
    
    @interface ViewController ()
    
    @property(nonatomic, strong)BMKMapManager * mapManager;
    @property(nonatomic, strong)BMKMapView * mapView;
    
    //地图类型
    @property (weak, nonatomic) IBOutlet UIButton *noneMap;
    @property (weak, nonatomic) IBOutlet UIButton *weixingMap;
    @property (weak, nonatomic) IBOutlet UIButton *morenMap;
    
    @property (weak, nonatomic) IBOutlet UIView *bgmapView;
    
    - (IBAction)nonButtonClick:(UIButton *)sender;
    - (IBAction)weixingButtonClick:(UIButton *)sender;
    - (IBAction)morenButtonClick:(UIButton *)sender;
    
    //交通现象
    @property (weak, nonatomic) IBOutlet UIButton *openTraffic;
    @property (weak, nonatomic) IBOutlet UIButton *closeTraffic;
    
    - (IBAction)openButtonClick:(UIButton *)sender;
    - (IBAction)closeButtonClick:(UIButton *)sender;
    
    //城市热力图
    @property (weak, nonatomic) IBOutlet UIButton *openCityHot;
    @property (weak, nonatomic) IBOutlet UIButton *closeCityHot;
    
    - (IBAction)openHotButton:(UIButton *)sender;
    - (IBAction)closeHotBUtton:(UIButton *)sender;
    
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        _mapManager = [[BMKMapManager alloc] init];
        BOOL result = [_mapManager start:@"自己的key" generalDelegate:nil];
        if (!result) {
            NSLog(@"Failed");
        }
        
    }
    
    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
        _mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-50)];
        [self.bgmapView addSubview:_mapView];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    /*
     BMKMapTypeNone       = 0,               ///< 空白地图
     BMKMapTypeStandard   = 1,               ///< 标准地图
     BMKMapTypeSatellite  = 2,               ///< 卫星地图
     */
    - (IBAction)nonButtonClick:(UIButton *)sender {
        _mapView.mapType = BMKMapTypeNone;
    }
    
    - (IBAction)morenButtonClick:(UIButton *)sender {
        _mapView.mapType = BMKMapTypeStandard;
    }
    
    - (IBAction)weixingButtonClick:(UIButton *)sender {
        _mapView.mapType = BMKMapTypeSatellite;
    }
    
    //交通显示
    - (IBAction)openButtonClick:(UIButton *)sender {
        [_mapView setTrafficEnabled:YES];
    }
    
    - (IBAction)closeButtonClick:(UIButton *)sender {
        [_mapView setTrafficEnabled:NO];
    }
    
    //城市热力图
    - (IBAction)openHotButton:(UIButton *)sender {
        [_mapView setBaiduHeatMapEnabled:YES];
    }
    
    - (IBAction)closeHotBUtton:(UIButton *)sender {
        [_mapView setBaiduHeatMapEnabled:NO];
    }
    @end
    

    慢慢学习,不要着急~

    相关文章

      网友评论

        本文标题:百度地图SDK学习——2.0 基本内容显示

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