ios 百度地图集成

用cocoapods导入百度地图

platform :ios, ‘8.0’

use_frameworks!

target 'mapBaiDu' do

pod 'AFNetworking'

pod 'BaiduMapKit','~> 3.2.1'

end


:wq保存退出


pod install



//

//  AppDelegate.m

//  mapBaiDu

//

//  Created by 孙璐 on 17/3/14.

//  Copyright © 2017年 孙璐. All rights reserved.

//


#import "AppDelegate.h"

#import <BaiduMapAPI_Base/BMKMapManager.h>

@interface AppDelegate ()

{

    BMKMapManager* _mapManager;

}

@end


@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    

    _mapManager = [[BMKMapManager alloc]init];

    // 如果要关注网络及授权验证事件,请设定     generalDelegate参数

    BOOL ret = [_mapManager start:@"申请的key"  generalDelegate:nil];

    if (!ret) {

        NSLog(@"manager start failed!");

    }

    return YES;

}

@end

//

//  ViewController.m

//  mapBaiDu

//

//  Created by 孙璐 on 17/3/14.

//  Copyright © 2017年 孙璐. All rights reserved.

//


#import "ViewController.h"

#import <BaiduMapAPI_Map/BMKMapView.h>

#import <BaiduMapAPI_Location/BMKLocationService.h>

@interface ViewController ()<BMKLocationServiceDelegate>

{

    BMKLocationService * locService;

    BMKMapView* mapView ;

}

@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

    [mapView setMapType:BMKMapTypeStandard];

    self.view = mapView;

    

    //初始化BMKLocationService

    locService = [[BMKLocationService alloc]init];

    locService.delegate = self;

    //启动LocationService

    [locService startUserLocationService];

    

    mapView.showsUserLocation = YES;//显示定位图层

    mapView.userTrackingMode = BMKUserTrackingModeHeading;

    [mapView setZoomLevel:25];

    

}

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{

   [mapView updateLocationData:userLocation];

    mapView.centerCoordinate = userLocation.location.coordinate;

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SL_Home

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值