iOS --百度地图定位后获取城市坐标,城市名称,区域名称

/**

 *用户位置更新后,会调用此函数

 *@param userLocation 新的用户位置

 */

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{    

    

    //定位当前城市

    BMKCoordinateRegion region;

    region.center.latitude  = userLocation.location.coordinate.latitude;

    region.center.longitude = userLocation.location.coordinate.longitude;

    region.span.latitudeDelta = 0;

    region.span.longitudeDelta = 0;

    NSLog(@"当前的坐标是:%f,%f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);

    

    CLGeocoder *geocoder = [[CLGeocoder alloc] init];

    [geocoder reverseGeocodeLocation: userLocation.location completionHandler:^(NSArray *array, NSError *error) {

        if (array.count > 0) {

            CLPlacemark *placemark = [array objectAtIndex:0];

            if (placemark != nil) {

                NSString *city = placemark.locality;

                

                NSLog(@"当前城市名称------%@",city);

                BMKOfflineMap * _offlineMap = [[BMKOfflineMap alloc] init];

               // _offlineMap.delegate = self;//可以不要

                NSArray* records = [_offlineMap searchCity:city];

                BMKOLSearchRecord* oneRecord = [records objectAtIndex:0];

                //城市编码如:北京为131

                NSInteger cityId = oneRecord.cityID;

                

                NSLog(@"当前城市编号-------->%zd",cityId);

                NSLog(@"当前城市的 哪个区------%@ ",placemark.subLocality);

                

                //找到了当前位置城市后就关闭服务

               // [_locService stopUserLocationService];

                

                

                


                

            }

        }

    }];

    

    

    

}



猜你喜欢

转载自blog.csdn.net/iotjin/article/details/79739140