TA的每日心情 | 汗 2024-10-15 10:05 |
---|
签到天数: 372 天 [LV.9]以坛为家II
|
本帖最后由 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 = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-
- SAViewController *viewController = [[SAViewController alloc] init];
-
- self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:viewController];
-
- _mapManager = [[BMKMapManager alloc]init];
-
- // 如果要关注网络及授权验证事件,请设定 generalDelegate参数
- BOOL ret = [_mapManager start:@"TutaWogwBPAKzWpPZOoNbecG" generalDelegate:nil];
- if (!ret) {
- NSLog(@"manager start failed!");
- }
-
- // Add the navigation controller's view to the window and display.
- [self.window addSubview:navigationController.view];
- [self.window makeKeyAndVisible];
- 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
- {
- [super viewDidLoad];
- self.title = @"百度地图";
- BMKMapView* mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 0)];
- self.view = mapView;
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
复制代码 SDK包:BaiduMapLib
链接: http://pan.baidu.com/s/1hqxdDic 密码: o8qe
源代码下载:
|
|