iOS 百度地图SDK使用小结

官方的集成介绍虽然很多,但是本人 用到的比较少,除了基本库的导入 和在AppDelegate离 regist外 其他用到的比较少,至少获取当前地理位置的代码 个人认为写的不够清除。


这里主要介绍下如何开启定位,反编码地理坐标 和城市云搜索。


BMKLocationServiceDelegate, BMKGeoCodeSearchDelegate


首页导入上面的代理方法

其次开启百度定位服务

 [BMKLocationService setLocationDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];

    [BMKLocationService setLocationDistanceFilter:kCLLocationAccuracyBest];

    

    //初始化BMKLocationService

    _locService = [[BMKLocationService alloc]init];

    _locService.delegate = self;

    //启动LocationService

    [_locService startUserLocationService];

调用代理方法会获取当前经纬度,获得经纬后 使用搜索 搜索坐标

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{


    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);

    // 建议获取完经纬后停止位置更新  否则会一直更新坐标

    if (userLocation.location.coordinate.latitude != 0) {

        [_locService stopUserLocationService];

    }

    //调用搜索

    BMKGeoCodeSearch *search = [[BMKGeoCodeSearch alloc]init];

    search.delegate = self;

    BMKReverseGeoCodeOption *rever = [[BMKReverseGeoCodeOption alloc]init];

    rever.reverseGeoPoint = userLocation.location.coordinate;

    //这段代码不要删

    NSLog(@"%d",[search reverseGeoCode:rever]);

}

搜索代理方法里就能返回具体地址了

#pragma mark GeoCodeResult 返回地理位置

-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error

{

    NSLog(@"%@",result.address);

}



以上就是获取当前地理位置的代码。



云搜索这块我是在使用系统正常的SearchBar,在它的代理方法里触发云搜索 导入代理

BMKGeoCodeSearchDelegate, BMKLocationServiceDelegate, BMKPoiSearchDelegate


- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

{

    //初始化poi搜索

    _poiSearch = [[BMKPoiSearch alloc]init];

    _poiSearch.delegate = self;

    

    BMKCitySearchOption *option = [[BMKCitySearchOption alloc]init];

    option.city = @"北京市";

    _searchTextFiled.placeholder = @"请输入要切换的地址";

    option.keyword = _searchTextFiled.text;

    BOOL flag = [_poiSearch poiSearchInCity:option];

    if(flag)

    {

//        NSLog(@"周边检索发送成功");

    }

    else

    {

//        NSLog(@"周边检索发送失败");

    }


}

- (void)onGetPoiResult:(BMKPoiSearch*)searcher

                result:(BMKPoiResult*)poiResultList

             errorCode:(BMKSearchErrorCode)error

{

    if (error == BMK_SEARCH_NO_ERROR) {

        //在此处理正常结果  poiResultList.totalPoiNum, poiResultList.poiInfoList 这两个分别代表搜索结果数量和存地址信息的数组, forin 遍历poiResultList.poiInfoList这个数组即可


        NSLog(@"%d %@", poiResultList.totalPoiNum, poiResultList.poiInfoList);

        NSArray *array = poiResultList.poiInfoList;

                

    }

    else if (error == BMK_SEARCH_AMBIGUOUS_KEYWORD){

        //当在设置城市未找到结果,但在其他城市找到结果时,回调建议检索城市列表

        // result.cityList;

        NSLog(@"起始点有歧义");

    } else {

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

        

    }

}

以上为城市云搜索代码,其他热点搜索等大家可以参考百度地图开发者中心里的类参考 查找即可。

如有疑问欢迎留言。


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值