百度地图SDK使用

百度地图其实和高德地图差不错,方法名也很像。

一、注册开发者帐号,下载百度SDK

注册开发者帐号很简单

SDK下载地址:http://lbsyun.baidu.com/index.php?title=iossdk/sdkiosdev-download

 

二、配置环境

110204_WjaZ_2625446.png

bundle identifier

110509_raPH_2625446.png

110510_Dus1_2625446.png

110512_tvLJ_2625446.png

获得AK

110205_TqPm_2625446.png

2.1可以手动添加framework,也可以使CocoaPods,我是手动。

添加

CoreLocation.framework

QuartzCore.framework

OpenGLES.framework

SystemConfiguration.framework

CoreGraphics.framework

Security.framework

libsqlite3.0.tbd(xcode7以前为 libsqlite3.0.dylib)

CoreTelephony.framework 

libstdc++.6.0.9.tbd(xcode7以前为libstdc++.6.0.9.dylib)

2.2在info.plist文件中添加

NSLocationAlwaysUsageDescription//不加有时定位会不成功

NSLocationWhenInUseUsageDescription//不加定位有时会不成功

App Transport Security Settings -- Allow Arbitrary Loads(YES);

Bundle display name 填写AK(APPKey)//会提示添加Bundle display name;

2.3千万记得在SDK里加上mapapi//会提示配置不完整,并且地图无法显示

110653_WMz9_2625446.png

#import "ViewController.h"
#import <BaiduMapAPI_Base/BMKBaseComponent.h>
#import <BaiduMapAPI_Map/BMKMapComponent.h>
#import <BaiduMapAPI_Search/BMKSearchComponent.h>
#import <BaiduMapAPI_Cloud/BMKCloudSearchComponent.h>
#import <BaiduMapAPI_Location/BMKLocationComponent.h>
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
#import <BaiduMapAPI_Radar/BMKRadarComponent.h>
#import <BaiduMapAPI_Map/BMKMapView.h>

#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
@interface ViewController ()<BMKMapViewDelegate,BMKLocationServiceDelegate>
{
    BMKMapManager *_mapManager;
    BMKMapView * _mapView;
    BMKLocationService * _loactionService;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createMapManager];
    
    [self createMap];
    
    [self loaction];

}

//初始化地图
- (void)createMapManager
{
    _mapManager = [[BMKMapManager alloc]init];
    BOOL result = [_mapManager start:@"应用的APPKey" generalDelegate:nil];
    if (!result) {
        NSLog(@"manager 初始化失败");
    }else
    {
        NSLog(@"manager 初始化成功");
    }
    
}

//创建地图
- (void)createMap
{
    _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    [self.view addSubview:_mapView];
    _mapView.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//定位
- (void)loaction
{
    _loactionService = [[BMKLocationService alloc]init];
    _loactionService.delegate = self;
    
}

//处理方向改变信息
-(void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{

}

//处理坐标位置更新
-(void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    NSLog(@"%f",userLocation.location.coordinate.latitude);
}
//卫星地图模式
- (IBAction)satelliteButton:(id)sender {
    
    [_mapView setMapType:BMKMapTypeSatellite];
}
@end

百度导航

添加

AudioToolbox.framework

ImageIO.framework

CoreMotion.framework

CoreLocation.framework

CoreTelephony.framework

MediaPlayer.framework

AVFoundation.framework

SystemConfiguration.framework

libstdc++6.0.9.dylib

Security.framework

JavaScriptCore.framework

build

配置

#import "AppDelegate.h"
#import "BNCoreServices.h"
- (void)createPlito
{
    NSString * baiduKey = [[LXJFrame readPlist:@"Confit" Type:@"plist"]objectForKey:@"baiduAppKey"][0];
    [BNCoreServices_Instance initServices:baiduKey];
    [BNCoreServices_Instance startServicesAsyn:nil fail:nil];

}
#import "PliotViewController.h"
#import "BaiduPliotHeader.h"

@interface PliotViewController ()<BNNaviRoutePlanDelegate,BNNaviUIManagerDelegate>
{

}
//导航类型 分为真实导航和模拟导航
@property (assign, nonatomic) BN_NaviType naviType;

@end

@implementation PliotViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createPageSet];
    [self createPageSet];
    [self getCoordinate];
    
}

#pragma mark - create
- (void)createPliotSet
{
    _naviType = BN_NaviTypeReal;
}

- (void)createPageSet
{
    self.title = @"导航";
    self.view.backgroundColor = [UIColor whiteColor];
}

- (BOOL)checkServicesInited
{
    if(![BNCoreServices_Instance isServicesInited])
    {
        UIAlertController * alerCT = [UIAlertController alertControllerWithTitle:@"提示" message:@"引擎尚未初始化完成,请稍后再试" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alerCT addAction:okAction];
        return NO;
    }
    return YES;
}

- (void)getCoordinate
{
    NSMutableArray * nodesArray = [[NSMutableArray alloc]init];
    
    BNRoutePlanNode *startNode = [[BNRoutePlanNode alloc] init];
    startNode.pos = [[BNPosition alloc] init];
    startNode.pos.x = 113.948222;
    startNode.pos.y = 22.549555;
    startNode.pos.eType = BNCoordinate_BaiduMapSDK;
    [nodesArray addObject:startNode];
    
    BNRoutePlanNode *endNode = [[BNRoutePlanNode alloc] init];
    endNode.pos = [[BNPosition alloc] init];
    endNode.pos.x = 114.089863;
    endNode.pos.y = 22.546236;
    endNode.pos.eType = BNCoordinate_BaiduMapSDK;
    [nodesArray addObject:endNode];
    
    [BNCoreServices_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Highway naviNodes:nodesArray time:nil delegete:self userInfo:nil];

}

#pragma mark - BNNaviRoutePlanDelegate
//算路成功回调
-(void)routePlanDidFinished:(NSDictionary *)userInfo
{
    [LXJFrame showMessage:@"路径规划成功" showTime:1.5];
    //路径规划成功,开始导航
    [BNCoreServices_UI showNaviUI:_naviType delegete:self isNeedLandscape:YES];
}

//算路失败回调
- (void)routePlanDidFailedWithError:(NSError *)error andUserInfo:(NSDictionary *)userInfo
{
    [LXJFrame showMessage:@"路径规划失败" showTime:1.5];
    if ([error code] == BNRoutePlanError_LocationFailed) {
        NSLog(@"获取地理位置失败");
    }
    else if ([error code] == BNRoutePlanError_LocationServiceClosed)
    {
        NSLog(@"定位服务未开启");
    }
}

//算路取消回调
-(void)routePlanDidUserCanceled:(NSDictionary*)userInfo {
    [LXJFrame showMessage:@"路径规划取消" showTime:1.5];
}

#pragma mark - BNNaviUIManagerDelegate

//退出导航回调
-(void)onExitNaviUI:(NSDictionary*)extraInfo
{
    [LXJFrame showMessage:@"退出导航" showTime:1.5];
}

要用真机测试

转载于:https://my.oschina.net/langzhouzhou1/blog/657906

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值