zoukankan      html  css  js  c++  java
  • IOS百度地图获取所在的城市名称

                笔者的app要实现定位所在省和城市名称,借此总结巩固一下!

               

    @interface VenueListVC : BasePageTableViewVC<BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate> {
        BMKLocationService *_locService;
        BMKGeoCodeSearch *_geoSearch;
        float _curLatitude, _curLongitude;
        NSString *_curCityName,*_curProName;
    
    - (void)viewDidLoad {
        //百度地图定位
        if (![CLLocationManager locationServicesEnabled]) {
            [UIAlertView showMsg:@"请在“系统设置”中开启定位服务" cancelText:@"确定" cancelAction:^{
                [self onBackButtonClick:nil];
            } okText:nil okAction:nil];
            return;
        }
        
        //初始化BMKLocationService
        if (_locService == nil) {
            _locService = [[BMKLocationService alloc]init];
        }
        _locService.delegate = self;
        //启动LocationService
        [_locService startUserLocationService];
        
        _geoSearch = [[BMKGeoCodeSearch alloc] init];
        //编码服务的初始化(就是获取经纬度,或者获取地理位置服务)
        _geoSearch.delegate = self;//设置代理为self
        //    [self showProgressHUDWithText:@"正在定位..."];
    
    //反向地理编码
    -(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
    {
        if (error == 0) {
            BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init];
            item.coordinate = result.location;
            item.title = result.address;
            NSString* titleStr;
            NSString* showmeg;
            titleStr = @"反向地理编码";
            showmeg = [NSString stringWithFormat:@"%@",item.title];
            _curCityName = result.addressDetail.city;
            _curProName = result.addressDetail.province;
            NSLog(result);
            }
    
    }
    //处理位置坐标更新
    - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
    {
        [_locService stopUserLocationService];
        
        CLLocationCoordinate2D coor;
        coor=userLocation.location.coordinate;
        _curLatitude = coor.latitude;
        _curLongitude = coor.longitude;
    
        CLLocationCoordinate2D pt = (CLLocationCoordinate2D){_curLatitude, _curLongitude};
        BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
        reverseGeocodeSearchOption.reverseGeoPoint = pt;
        [_geoSearch reverseGeoCode:reverseGeocodeSearchOption];
        
        
    }
    
    /**
     *定位失败后,会调用此函数
     *@param error 错误号
     */
    - (void)didFailToLocateUserWithError:(NSError *)error {
        [_locService stopUserLocationService];
        [self hideProgressHUD];
    }

            

  • 相关阅读:
    读胶料温度代码
    干掉win10自带的不给力的应用(转自https://jingyan.baidu.com/article/08b6a591b7398514a8092238.html)
    安装SQL提示重启电脑失败,解决办法
    几种加解密方法:AES、DES、SHA数据加密
    SQL数据库添加新账号,只操作指定数据库
    jQuery中attr()、prop()、data()用法及区别
    jquery.cookie() 的使用(原)
    功能强大的web打印控件lodop的使用
    Win+R命令大全
    Vue
  • 原文地址:https://www.cnblogs.com/HQBBOX/p/5311599.html
Copyright © 2011-2022 走看看