ios 百度地图集成

来源:互联网 发布:大熊猫脾气 知乎 编辑:程序博客网 时间:2024/06/10 07:50

用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 = [[BMKMapManageralloc]init];

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

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

    if (!ret) {

        NSLog(@"manager start failed!");

    }

    returnYES;

}

@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 {

    [superviewDidLoad];

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

    

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

    [mapViewsetMapType:BMKMapTypeStandard];

    self.view =mapView;

    

    //初始化BMKLocationService

    locService = [[BMKLocationServicealloc]init];

    locService.delegate =self;

    //启动LocationService

    [locServicestartUserLocationService];

    

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

    mapView.userTrackingMode =BMKUserTrackingModeHeading;

    [mapViewsetZoomLevel:25];

    

}

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{

   [mapViewupdateLocationData:userLocation];

    mapView.centerCoordinate = userLocation.location.coordinate;

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end

0 0
原创粉丝点击