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

            

  • 相关阅读:
    css3小叮当(转载)
    三大Flex布局用法(转载)
    移动前端:移动端页面坑与排坑技巧
    最好的前端开发资源推荐(转载)
    高效CSS开发核心要点摘录
    css常用代码大全以及css兼容(转载)
    如何处理CSS3属性前缀(转载)总结
    前端制作入门知识(转载)
    移动前端页面制作技巧(一)转载
    sass揭秘之@mixin,%,@function(转载)
  • 原文地址:https://www.cnblogs.com/HQBBOX/p/5311599.html
Copyright © 2011-2022 走看看