//
//  PoiViewController.m
//  baiDuDemo
//
//  Created by City--Online on 15/6/4.
//  Copyright (c) 2015年 XQB. All rights reserved.
//

#import "PoiViewController.h"
#import "BMKTypes.h"
#import "BMKPoiSearch.h"
#import "BMKBusLineSearch.h"
#import "BMKGeocodeSearch.h"
@interface PoiViewController ()<BMKPoiSearchDelegate,BMKGeoCodeSearchDelegate,UITableViewDataSource,UITableViewDelegate>
//周边、详情搜索
@property(nonatomic,strong) BMKPoiSearch *searcher;
//周边搜索条件
@property(nonatomic,strong) BMKNearbySearchOption *nearbySearchOption;
//详情搜索条件
@property(nonatomic,strong) BMKPoiDetailSearchOption *detailSearchOption;

@property(nonatomic,strong) UITableView *tableView;
//周边搜索列表数据
@property(nonatomic,strong) NSMutableArray *poiInfoList;

//地理信息编码
@property(nonatomic,strong) BMKGeoCodeSearch *geoCodeSearch;

@end

@implementation PoiViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //初始化检索对象
    _searcher =[[BMKPoiSearch alloc]init];
    _searcher.delegate = self;
    //发起周边检索
    _nearbySearchOption = [[BMKNearbySearchOption alloc]init];
//    _nearbySearchOption.pageIndex = 1;
//    _nearbySearchOption.pageCapacity = 10;
    _nearbySearchOption.location=CLLocationCoordinate2DMake(22.5538, 114.0672);
    _nearbySearchOption.radius=;
    _nearbySearchOption.sortType=BMK_POI_SORT_BY_DISTANCE;
    _nearbySearchOption.keyword = @"小吃";
    BOOL flag = [_searcher poiSearchNearBy:_nearbySearchOption];

    if(flag)
    {
        NSLog(@"周边检索发送成功");
    }
    else
    {
        NSLog(@"周边检索发送失败");
    }

    // 地理信息编码
    _geoCodeSearch =[[BMKGeoCodeSearch alloc]init];
    _geoCodeSearch.delegate = self;
    BMKGeoCodeSearchOption *geoCodeSearchOption = [[BMKGeoCodeSearchOption alloc]init];
    geoCodeSearchOption.city= @"深圳市";
    geoCodeSearchOption.address = @"音乐厅";
    flag = [_geoCodeSearch geoCode:geoCodeSearchOption];
    if(flag)
    {
        NSLog(@"geo检索发送成功");
    }
    else
    {
        NSLog(@"geo检索发送失败");
    }

    // 地理信息反编码
    CLLocationCoordinate2D pt = (CLLocationCoordinate2D){22.588393, 113.946523};
    BMKReverseGeoCodeOption *reverseGeoCodeSearchOption = [[
    BMKReverseGeoCodeOption alloc]init];
    reverseGeoCodeSearchOption.reverseGeoPoint = pt;
    flag = [_geoCodeSearch reverseGeoCode:reverseGeoCodeSearchOption];
    if(flag)
    {
      NSLog(@"反geo检索发送成功");
    }
    else
    {
      NSLog(@"反geo检索发送失败");
    }

    _tableView =[[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    _tableView.dataSource=self;
    _tableView.delegate=self;
    [self.view addSubview:_tableView];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

        return _poiInfoList.count;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    BMKPoiInfo *poiInfo=[_poiInfoList objectAtIndex:indexPath.row];
    cell.textLabel.text=[NSString stringWithFormat:@"%@ %@",poiInfo.name,poiInfo.uid];
   return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

        //发起详情搜索
        _detailSearchOption=[[BMKPoiDetailSearchOption alloc]init];
        BMKPoiInfo *poiInfo=[_poiInfoList objectAtIndex:indexPath.row];
        _detailSearchOption.poiUid=poiInfo.uid;
        BOOL flag = [_searcher poiDetailSearch:_detailSearchOption];
        if(flag)
        {
            NSLog(@"详情检索发起成功");
            //详情检索发起成功
        }
        else
        {
            NSLog(@"详情检索发送失败");
            //详情检索发送失败
        }

}
//周边搜索
- (void)onGetPoiResult:(BMKPoiSearch*)searcher result:(BMKPoiResult*)poiResult errorCode:(BMKSearchErrorCode)errorCode
{
    if (errorCode == BMK_SEARCH_NO_ERROR) {
        _poiInfoList=[poiResult.poiInfoList mutableCopy];
        [_tableView reloadData];
        NSLog(@"%d %d %d %d",poiResult.totalPoiNum,poiResult.currPoiNum,poiResult.pageNum,poiResult.pageIndex);
        for (BMKPoiInfo *poiInfo in poiResult.poiInfoList) {
            NSLog(@"name:%@  UId:%@",poiInfo.name,poiInfo.uid);

        }
        for (BMKCityListInfo *CityListInfo in poiResult.cityList) {
            NSLog(@"%@",CityListInfo.city);
        }

    }
    else if (errorCode == BMK_SEARCH_AMBIGUOUS_KEYWORD){
        //当在设置城市未找到结果,但在其他城市找到结果时,回调建议检索城市列表
        // result.cityList;
        NSLog(@"起始点有歧义");
    } else {
        NSLog(@"抱歉,未找到结果");
    }
}
//详情搜索
- (void)onGetPoiDetailResult:(BMKPoiSearch*)searcher result:(BMKPoiDetailResult*)poiDetailResult errorCode:(BMKSearchErrorCode)errorCode
{
    if (errorCode == BMK_SEARCH_NO_ERROR) {
        NSLog(@"%@ %@ %@ %@",poiDetailResult.name,poiDetailResult.address,poiDetailResult.phone,poiDetailResult.shopHours);
        NSString *message=[NSString stringWithFormat:@"店名:%@ \n地址:%@\n 电话:%@\n 营业时间:%@\n经纬度:%lf %lf",poiDetailResult.name,poiDetailResult.address,poiDetailResult.phone,poiDetailResult.shopHours,poiDetailResult.pt.latitude,poiDetailResult.pt.longitude];
        UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"搜索详情" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];

    }
    else if (errorCode == BMK_SEARCH_AMBIGUOUS_KEYWORD){
        //当在设置城市未找到结果,但在其他城市找到结果时,回调建议检索城市列表
        // result.cityList;
        NSLog(@"起始点有歧义");
    } else {
        NSLog(@"抱歉,未找到结果");
    }

}
- (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
    if (error == BMK_SEARCH_NO_ERROR) {
        NSLog(@"%lf %lf %@",result.location.latitude,result.location.longitude,result.address);
    }
    else {
        NSLog(@"抱歉,未找到结果");
    }

}
- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
      if (error == BMK_SEARCH_NO_ERROR) {
          NSLog(@"%@",result.address);
          for (BMKPoiInfo *poiInfo in result.poiList) {
              NSLog(@"%@ %@",poiInfo.name,poiInfo.address);
          }

      }
      else {
          NSLog(@"抱歉,未找到结果");
      }    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any_ resources that can be recreated.
}

@end

百度地图之POI的更多相关文章

  1. Android学习笔记之使用百度地图实现Poi搜索

    PS:装个系统装了一天.心力憔悴.感觉不会再爱了. 学习内容: 1.使用百度Map实现Poi搜索. 2.短串分享 3.在线建议查询   百度地图的研究也算是过半了.能够实现定位,实现相关信息的搜索,实 ...

  2. 教你如何拔取百度地图POI兴趣点

    教你如何拔取百度地图POI兴趣点   通过聚合数据提供的接口,获取百度地图的POI兴趣点,并存储至数据库中. 实现: 1.聚合数据百度POI接口说明 调用聚合数据,首先得注册聚合.聚合数据提供的百度地 ...

  3. 百度地图开发之POI数据检索

    前面学习百度地图的一些基本的用法,这次我们一起来看一看百度地图的检索功能吧 poi检索api的基本用法 百度地图的POI类中共有如下几个方法 PoiBoundSearchOption POI范围内检索 ...

  4. 获取百度地图POI数据二(准备搜索关键词)

    上篇讲到  想要获取尽可能多的POI数据 需要准备尽可能多的搜索关键字   那么这些关键字如何得来呢?   本人使用的方法是通过一些网站来获取这些关键词   http://poi.mapbar.com ...

  5. 百度地图POI数据爬取,突破百度地图API爬取数目“400条“的限制11。

    1.POI爬取方法说明 1.1AK申请 登录百度账号,在百度地图开发者平台的API控制台申请一个服务端的ak,主要用到的是Place API.检校方式可设置成IP白名单,IP直接设置成了0.0.0.0 ...

  6. iOS第三方地图-百度地图常用功能使用(POI搜索,地理正反编码,定位,添加标注)

    百度地图官网: http://developer.baidu.com/map/index.php?title=iossdk 百度地图集成 1.引入相关包

  7. (转载) 百度地图工具类封装(包括定位,附近、城市、范围poi检索,反地理编码)

    目录视图 摘要视图 订阅 赠书 | 异步2周年,技术图书免费选      程序员8月书讯      项目管理+代码托管+文档协作,开发更流畅 百度地图工具类封装(包括定位,附近.城市.范围poi检索, ...

  8. IOS_OC_百度地图与社交分享

    前奏. 知识点介绍 一. 导航和画线 地图画线 (理解) 二. 百度地图 集成百度地图 (掌握) POI检索 (掌握) 三. 社交分享 系统自带分享 (了解) 友盟分享 (掌握) SSO授权 (理解) ...

  9. 百度地图Key的设置方法

    一.为什么要设置百度Key 万能地图下载器提供了百度POI的下载功能,但由于本软件用户群极大,会导致一天之内访问量超出300万次以上而无法继续下载. 因此,当POI下载不成功能,用户可以自己申请百度地 ...

随机推荐

  1. 带Left Join的SQL语句的执行顺序

    基础的SQL执行顺序 SQL语句执行的时候是有一定顺序的.理解这个顺序对SQL的使用和学习有很大的帮助. 1.from 先选择一个表,或者说源头,构成一个结果集. 2.where 然后用where对结 ...

  2. BGP学习笔记

    源自红茶三杯: BGP应用于大规模网络或运营商,用作在AS间传递路由信息 使用BGP的三大理由 1. 大量路由需要承载, IGP只能容纳千条,而BGP可以容纳上万(应该是IGP结合BGP使用?) 2. ...

  3. python 解析XML python模块xml.dom解析xml实例代码

    分享下python中使用模块xml.dom解析xml文件的实例代码,学习下python解析xml文件的方法. 原文转自:http://www.jbxue.com/article/16587.html ...

  4. Oracle表变化趋势追踪记录

    #DBA_HIST_SEG_STAT可以看出对象的使用趋势,构造如下SQL查询出每个时间段内数据库对象的增长量,其中DB_BLOCK_CHANGES_DELTA为块个数 select c.SNAP_I ...

  5. iOS开发常用的宏

    #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)#define SCREEN_HEIGHT ([UIScreen mainS ...

  6. stm32f103 SPI单线TX发数据来驱动LCD

    有一黑白LCD,有CS/SI/SCK三线,时序满足SPI时序,但STM32的SPI有四线NSS/MOSI/SCK/MISO,这里MISO没有用到.因此可以使用SPI的单线发送模式进行驱动LCD. 关键 ...

  7. Multi-Language IDE for Professional Developers (Komodo)

    Komodo is the professional IDE for major web languages, including Python, PHP, Ruby, Perl, HTML, CSS ...

  8. python Django 学习笔记(三)—— 模版的使用

    模版基本介绍 模板是一个文本,用于分离文档的表现形式和内容. 模板定义了占位符以及各种用于规范文档该如何显示的各部分基本逻辑(模板标签). 模板通常用于产生HTML,但是Django的模板也能产生任何 ...

  9. Win8.1想要卸载openSUSE出现问题(2014.8.15已解决)

    用DiskGenius激活C盘后果然好用了!随便用EasyBCD恢复一下就好了 下面再说说安装openSUSE这半周多的问题: 1.如果是NVIDIA和Intel双显卡就不要安装NVIDIA的显卡驱动 ...

  10. SAP B1 ADDON 开发

    承接各类SAP B1 ADDON 开发. 有需要,请联系.