百度地图之POI

简介:

//
//  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=5000;
    _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



相关文章
|
Java API Android开发
【POI框架实战】——POI设置Excel单元格格式
 “这个excel中的数据怎么不能做加法啊?”、“标头这一行的字体怎么这么小啊,我都看不清”、“这一列能不能换个颜色,明显一些”、“你把这一列的数据给我留两个小数位。”、“这些数据能不能以货币的类型展示啊,就每个三位一个小逗号那种……”
【POI框架实战】——POI设置Excel单元格格式
|
2月前
|
Java
使用POI导出Excel
使用POI导出Excel
|
6月前
|
Python
超详细讲解ArcGIS中根据POI点识别功能区
超详细讲解ArcGIS中根据POI点识别功能区
156 0
|
9月前
|
定位技术
百度地图开发实战案例:展示当前定位多少千米内的POI(兴趣点)
百度地图开发实战案例:展示当前定位多少千米内的POI(兴趣点)
61 0
|
9月前
|
存储 JSON 定位技术
城市POI数据爬取-百度地图版
目前百度地图的最新版为地图检索V2.0服务。详细介绍可以通过开发文档-web服务Api-地点检索V2.0获取。
|
12月前
|
定位技术 数据安全/隐私保护
POI点获取
POI点POI是“Point of Information”的缩写,中文可以翻译为“信息点”。在地理信息系统中,一个POI可以是一栋房子、一个商铺、一个邮筒、一个公交站等
179 0
|
程序员 计算机视觉
一次简单的poi导出Excel实践
一次简单的poi导出Excel实践
|
小程序 定位技术
微信小程序 腾讯地图逆地址解析reverseGeocoder之poi_options
微信小程序 腾讯地图逆地址解析reverseGeocoder之poi_options
1857 0
微信小程序 腾讯地图逆地址解析reverseGeocoder之poi_options
|
XML Java 应用服务中间件
来,通过 Excel 来认识神器——POI
来,通过 Excel 来认识神器——POI
221 0
来,通过 Excel 来认识神器——POI