zoukankan      html  css  js  c++  java
  • (八十四)集成百度地图和基本使用

    配置的详细内容可以查看百度地图API文档来获取。

    ①首先下载百度iOS SDK的完整包,将其中Lib的Release-iphonesimulator下的framework文件导入到工程,然后双击打开framework文件,再打开Resources,将其中的mapapi.bundle导入到工程。

    ②从系统设置中导入下列框架:

    ③在Build Settings里搜索other linker Flags,添加-ObjC标记。

    ④因为静态库用到了C++,因此工程中必须有mm文件,最简单的方法是把其中一个m文件改成mm。

    ⑤对于Xcode6和以后的版本,还需要在info.plist中加入Bundle display name,值随便写,一般写Bundle identifier的值。

    ⑥在AppDelegate中创建管理者,然后启动,需要传入key。

    #import "AppDelegate.h"
    
    @interface AppDelegate ()
    
    @property (nonatomic, strong) BMKMapManager *mapManager;
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        
        _mapManager = [[BMKMapManager alloc] init];
        BOOL ret = [_mapManager start:@"这里填写key" generalDelegate:self];
        if (!ret) {
            NSLog(@"manager start failed");
        }
        
        return YES;
    }
    
    
    @end

    Tip:key和bundle identify的值应该和申请开发者时创建的应用内的一致,否则无法正常的授权。

    ⑦显示地图和基本使用

    下面的代码创建了MapView和Poisearch,实现了地图的显示和POI检索。

    #import "ViewController.h"
    #import <BaiduMapAPI/BMapKit.h>
    
    @interface ViewController () <BMKMapViewDelegate,BMKPoiSearchDelegate>
    
    @property (nonatomic, weak) BMKMapView *mapView;
    @property (nonatomic, strong) BMKPoiSearch *searcher;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        BMKMapView* mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 20, 320, 420)];
        [self.view addSubview:mapView];
        _mapView  = mapView;
        
        _searcher = [[BMKPoiSearch alloc] init];
        _searcher.delegate = self;
        
    }
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [_mapView viewWillAppear];
        _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
    }
    
    - (void)viewWillDisappear:(BOOL)animated
    {
        [_mapView viewWillDisappear];
        _mapView.delegate = nil; // 不用时,置nil
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        
        NSLog(@"in");
        
        // 检索周边信息
        BMKCitySearchOption *option = [[BMKCitySearchOption alloc] init];
        option.pageIndex = 0;
        option.pageCapacity = 10;
        option.city = @"北京";
        option.keyword = @"小吃";
        BOOL flag = [_searcher poiSearchInCity:option];
        if(flag)
        {
            NSLog(@"周边检索发送成功");
        }
        else
        {
            NSLog(@"周边检索发送失败");
        }
    }
    
    - (void)onGetPoiResult:(BMKPoiSearch *)searcher result:(BMKPoiResult*)result errorCode:(BMKSearchErrorCode)error
    {
        // 清楚屏幕中所有的annotation
        NSArray* array = [NSArray arrayWithArray:_mapView.annotations];
        [_mapView removeAnnotations:array];
        
        if (error == BMK_SEARCH_NO_ERROR) {
            NSMutableArray *annotations = [NSMutableArray array];
            for (int i = 0; i < result.poiInfoList.count; i++) {
                BMKPoiInfo* poi = [result.poiInfoList objectAtIndex:i];
                BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init];
                item.coordinate = poi.pt;
                item.title = poi.name;
                [annotations addObject:item];
            }
            [_mapView addAnnotations:annotations];
            [_mapView showAnnotations:annotations animated:YES];
        } else if (error == BMK_SEARCH_AMBIGUOUS_ROURE_ADDR){
            NSLog(@"起始点有歧义");
        } else {
            // 各种情况的判断。。。
        }
    }
    
    @end
    

  • 相关阅读:
    鼠标和滚轮事件
    UI事件
    跨浏览器的事件对象
    DOM中的事件对象和IE事件对象
    Monolog手册参考
    nginx 配置
    es elasticsearch-head安装
    es ik分词插件安装
    yii2.0+es
    php分词工具scws
  • 原文地址:https://www.cnblogs.com/aiwz/p/6154115.html
Copyright © 2011-2022 走看看