年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3700|回复: 0

百度地图iOS SDK使用

[复制链接]
  • TA的每日心情

    2024-10-15 10:05
  • 签到天数: 372 天

    [LV.9]以坛为家II

    发表于 2014-7-23 17:35:55 | 显示全部楼层 |阅读模式
    本帖最后由 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
    1. //
    2. //  SAAppDelegate.h
    3. //  MapTest
    4. //
    5. //  Created by yusian on 14-7-23.
    6. //  Copyright (c) 2014年 小龙虾论坛. All rights reserved.
    7. //
    8. #import <UIKit/UIKit.h>
    9. @interface SAAppDelegate : UIResponder <UIApplicationDelegate>
    10. {
    11.     UINavigationController *navigationController;
    12.     BMKMapManager* _mapManager;
    13. }
    14. @property (strong, nonatomic) UIWindow *window;
    15. @end
    复制代码
    SAAppDelegate.m
    1. //
    2. //  SAAppDelegate.m
    3. //  MapTest
    4. //
    5. //  Created by yusian on 14-7-23.
    6. //  Copyright (c) 2014年 小龙虾论坛. All rights reserved.
    7. //
    8. #import "SAAppDelegate.h"
    9. #import "SAViewController.h"
    10. @implementation SAAppDelegate
    11. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    12. {
    13.    
    14.     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    15.    
    16.     SAViewController *viewController = [[SAViewController alloc] init];
    17.    
    18.     self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:viewController];
    19.    
    20.     _mapManager = [[BMKMapManager alloc]init];
    21.    
    22.     // 如果要关注网络及授权验证事件,请设定     generalDelegate参数
    23.     BOOL ret = [_mapManager start:@"TutaWogwBPAKzWpPZOoNbecG"  generalDelegate:nil];
    24.     if (!ret) {
    25.         NSLog(@"manager start failed!");
    26.     }
    27.    
    28.     // Add the navigation controller's view to the window and display.
    29.     [self.window addSubview:navigationController.view];
    30.     [self.window makeKeyAndVisible];
    31.     return YES;
    32. }
    33.                                                         
    34. - (void)applicationWillResignActive:(UIApplication *)application
    35. {
    36.     // 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.
    37.     // 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.
    38. }
    39. - (void)applicationDidEnterBackground:(UIApplication *)application
    40. {
    41.     // 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.
    42.     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    43. }
    44. - (void)applicationWillEnterForeground:(UIApplication *)application
    45. {
    46.     // 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.
    47. }
    48. - (void)applicationDidBecomeActive:(UIApplication *)application
    49. {
    50.     // 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.
    51. }
    52. - (void)applicationWillTerminate:(UIApplication *)application
    53. {
    54.     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    55. }
    56. @end
    复制代码
    SAViewController.h
    1. //
    2. //  SAViewController.h
    3. //  MapTest
    4. //
    5. //  Created by yusian on 14-7-23.
    6. //  Copyright (c) 2014年 小龙虾论坛. All rights reserved.
    7. //
    8. #import <UIKit/UIKit.h>
    9. @interface SAViewController : UIViewController
    10. @end
    复制代码
    SAViewController.mm
    1. //
    2. //  SAViewController.m
    3. //  MapTest
    4. //
    5. //  Created by yusian on 14-7-23.
    6. //  Copyright (c) 2014年 小龙虾论坛. All rights reserved.
    7. //
    8. #import "SAViewController.h"
    9. @interface SAViewController ()
    10. @end
    11. @implementation SAViewController
    12. - (void)viewDidLoad
    13. {
    14.     [super viewDidLoad];
    15.     self.title = @"百度地图";
    16.     BMKMapView* mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 0)];
    17.     self.view = mapView;
    18. }
    19. - (void)didReceiveMemoryWarning
    20. {
    21.     [super didReceiveMemoryWarning];
    22.     // Dispose of any resources that can be recreated.
    23. }
    24. @end
    复制代码
    SDK包:BaiduMapLib
    链接: http://pan.baidu.com/s/1hqxdDic 密码: o8qe
    源代码下载:
    游客,如果您要查看本帖隐藏内容请回复




    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-11-23 05:35 , Processed in 0.059388 second(s), 24 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表