ios 百度地图集成

用cocoapods导入百度地图

platform :ios, ‘8.0’

use_frameworks!

target 'mapBaiDu' do

pod 'AFNetworking'

pod 'BaiduMapKit','~> 3.2.1'

end


:wq保存退出


pod install

扫描二维码关注公众号,回复: 2707118 查看本文章



//

//  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

猜你喜欢

转载自blog.csdn.net/qq_30737525/article/details/62043484