一起玩地图

地图的分类: 百度地图 腾讯地图 高德地图 苹果本身

http://developer.baidu.com/map/ (详情请查看网站)

  • 我们使用的是百度地图
  • 在终端里输入pod search baidumap
  • 把代码引到podfile里
    pod 'BaiduMap-iOS-SDK', '~> 2.8.1.1'
  • 在终端输入指令,把百度地图的库导入工程里
    pod update --verbose --no-repo-update
  • 在build settings 中添加
    $(SRCROOT)
  • 申请秘钥 http://lbsyun.baidu.com/apiconsole/key
  • 由于iOS9改用更安全的https,为了能够在iOS9中正常使用地图SDK,请在"Info.plist"中进行如下配置,否则影响SDK的使用。双击open AS/ Sourcd code
  NSAppTransportSecurity
    
        NSAllowsArbitraryLoads
        
    
  • 如果在iOS9中使用了调起百度地图客户端功能,必须在"Info.plist"中进行如下配置,否则不能调起百度地图客户端。
LSApplicationQueriesSchemes
    
        baidumap
    
  • 在使用BMKMapView的viewController中需要在viewWillAppear、viewWillDisappear方法中调用BMKMapView的对应的方法,并处理delegate
(void)viewWillAppear:(BOOL)animated      
{      
    [_mapView viewWillAppear];      
    _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放      
}      
-(void)viewWillDisappear:(BOOL)animated      
{      
        [_mapView viewWillDisappear];      
      _mapView.delegate = nil; // 不用时,置nil      
}
  • 初始化BMKMapManager 在当前文件中的.h文件中添加BMKMapManager的定义
@interface BaiduMapApiDemoAppDelegate : NSObject  {   
       UIWindow *window;    
       UINavigationController *navigationController;     
       BMKMapManager* _mapManager;    
}```
 * 在当前文件中添加对BMKMapManager的初始化,并填入您申请的授权Key,示例如下http://lbsyun.baidu.com/apiconsole/key ,在.h中写代理方法``BMKMapViewDelegate``定义一个变量``    BMKMapManager* _mapManager;
``

_mapManager = [[BMKMapManager alloc]init];
// 如果要关注网络及授权验证事件,请设定 generalDelegate参数
BOOL ret = [_mapManager start:@"sH4enIjfG585foGEtlIghsog" generalDelegate:nil];
if (!ret) {
NSLog(@"manager start failed!");
}```

  • 在当前的ViewController.m文件中添加BMKMapView的创建代码,示例如下
 _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    _mapView.centerCoordinate =CLLocationCoordinate2DMake(38.8496481, 121.517977);
    _mapView.zoomLevel = 15;
  • 正常应该有15个红 我们只需要把任意的ViewController.m 改成ViewController.mm

你可能感兴趣的:(一起玩地图)