百度LBS官方入门的实践(1)

百度官方流程:http://developer.baidu.com/map/sdkiosdev-1.htm#.E7.AE.80.E4.BB.8B3

http://developer.baidu.com/map/sdkiosdev-2.htm


今天跟着百度LBS的官方走了一遍地图初始的应用设置。

首先必然是从百度下载官方的sdk,在官方申请新的key,如图:


类型,因为是移动应用,所以我选择的是For Mobile,引入静态库、frame神马的,直接走就行,比较重要的,一个是otherLinkerFlags必须加-ObjC,另一个就是项目里必须有个.mm文件,随便弄一个没用的就ok。


接下来就贴代码了:

AppDelegate:

#import <UIKit/UIKit.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate,BMKMapViewDelegate>


@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) BMKMapManager *mapManager;

@end


.m文件:

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

{

    _mapManager = [[BMKMapManager alloc]init];

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

    BOOL ret = [_mapManager start:@"baidu分给你的key"  generalDelegate:nil];

    if (!ret) {

        NSLog(@"manager start failed!");

    }

    return YES;

}



viewController.h:

#import <UIKit/UIKit.h>


@interface ViewController : UIViewController


@property(strong,nonatomic)BMKMapView* mapView;

@end


.m文件:

#import "ViewController.h"


@interface ViewController ()

@property(strong,nonatomic) id <BMKMapViewDelegate> delegate;

@end


@implementation ViewController

@synthesize mapView;

@synthesize delegate;

-(void)viewWillAppear:(BOOL)animated

{

    [mapView viewWillAppear];

    mapView.delegate = delegate;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    CGRect frame=self.view.frame;

     mapView = [[BMKMapView alloc]initWithFrame:frame];

    self.view = mapView;

}


-(void)viewWillDisappear:(BOOL)animated

{

    [mapView viewWillDisappear];

    mapView.delegate = nil;

}


    结果和baidu给的运行结果相同。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

limaning

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

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

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

打赏作者

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

抵扣说明:

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

余额充值