Sian 发表于 2014-7-23 17:35:55

百度地图iOS SDK使用

本帖最后由 Sian 于 2015-9-22 10:03 编辑

1、申请百度帐号(略);
2、申请密钥 http://lbsyun.baidu.com/apiconsole/key 即在百度创建一个应用,不用多说开发者都明白;
3、下载SDK包,http://developer.baidu.com/map/sdk-ios.htm
4、编写 Hello BaiduMap
SAAppDelegate.h
//
//SAAppDelegate.h
//MapTest
//
//Created by yusian on 14-7-23.
//Copyright (c) 2014年 小龙虾论坛. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SAAppDelegate : UIResponder <UIApplicationDelegate>
{
    UINavigationController *navigationController;
    BMKMapManager* _mapManager;
}
@property (strong, nonatomic) UIWindow *window;

@end
SAAppDelegate.m
//
//SAAppDelegate.m
//MapTest
//
//Created by yusian on 14-7-23.
//Copyright (c) 2014年 小龙虾论坛. All rights reserved.
//

#import "SAAppDelegate.h"
#import "SAViewController.h"

@implementation SAAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   
    self.window = [ initWithFrame:[ bounds]];
   
    SAViewController *viewController = [ init];
   
    self.window.rootViewController = [ initWithRootViewController:viewController];
   
    _mapManager = [init];
   
    // 如果要关注网络及授权验证事件,请设定   generalDelegate参数
    BOOL ret = ;
    if (!ret) {
      NSLog(@"manager start failed!");
    }
   
    // Add the navigation controller's view to the window and display.
    ;
    ;
    return YES;
}
                                                      
- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
SAViewController.h
//
//SAViewController.h
//MapTest
//
//Created by yusian on 14-7-23.
//Copyright (c) 2014年 小龙虾论坛. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SAViewController : UIViewController

@end
SAViewController.mm
//
//SAViewController.m
//MapTest
//
//Created by yusian on 14-7-23.
//Copyright (c) 2014年 小龙虾论坛. All rights reserved.
//

#import "SAViewController.h"

@interface SAViewController ()

@end

@implementation SAViewController

- (void)viewDidLoad
{
    ;
    self.title = @"百度地图";
    BMKMapView* mapView = [initWithFrame:CGRectMake(0, 0, 320, 0)];
    self.view = mapView;
}

- (void)didReceiveMemoryWarning
{
    ;
    // Dispose of any resources that can be recreated.
}

@end
SDK包:BaiduMapLib
链接: http://pan.baidu.com/s/1hqxdDic 密码: o8qe
源代码下载:
**** Hidden Message *****



页: [1]
查看完整版本: 百度地图iOS SDK使用