這次寫的是,對于百度地圖顯示內(nèi)容的基本認(rèn)識。基本就是按照官方文檔學(xué)習(xí)的,話不多說,開始看代碼。
本文是根據(jù)1.0內(nèi)容接著寫的
布局

布局
地圖類型
類型有三種
BMKMapTypeNone = 0, ///< 空白地圖
BMKMapTypeStandard = 1, ///< 標(biāo)準(zhǔn)地圖
BMKMapTypeSatellite = 2, ///< 衛(wèi)星地圖
空白地圖

空白地圖
標(biāo)準(zhǔn)地圖(默認(rèn))

默認(rèn)地圖
衛(wèi)星地圖

衛(wèi)星地圖
-
調(diào)用的方法是
當(dāng)前地圖類型,可設(shè)定為標(biāo)準(zhǔn)地圖、衛(wèi)星地圖
@property (nonatomic) BMKMapType mapType;
_mapView.mapType = 地圖類型;
交通狀況
打開交通狀況

打開交通狀況
關(guān)閉交通狀況

關(guān)閉交通狀況
調(diào)用的方法
設(shè)定地圖是否打開路況圖層
@property(nonatomic, getter=isTrafficEnabled) BOOL trafficEnabled;
[_mapView setTrafficEnabled:YES/NO];
城市熱力圖
打開熱力圖

打開熱力圖
關(guān)閉熱力圖

關(guān)閉熱力圖
調(diào)用的方法
設(shè)定地圖是否打開百度城市熱力圖圖層(百度自有數(shù)據(jù)),注:地圖層級大于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;
//交通現(xiàn)象
@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, ///< 標(biāo)準(zhǔn)地圖
BMKMapTypeSatellite = 2, ///< 衛(wèi)星地圖
*/
- (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
慢慢學(xué)習(xí),不要著急~