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];
    }

            

  • 相关阅读:
    tomcat日志信息查看
    "".equals(xxx)和xxx.equals("")的区别
    javax.crypto.BadPaddingException: Given final block not properly padded解决方案
    去掉first li 的list图标
    浮动后的 <li> 如何在 <ul> 中居中显示?
    java冒泡排序
    JSP获取网络IP地址
    <%@ include %>导入的文件乱码
    out.print()与response.sendRedirect()
    王爽汇编语言第三版第5章实验4
  • 原文地址:https://www.cnblogs.com/HQBBOX/p/5311599.html
Copyright © 2011-2022 走看看