IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息

IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息

/**当获取到定位的坐标后,回调函数*/

- (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);

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

                [_locService stopUserLocationService];

                

            }

        }

    }];

    

}

原文地址:https://www.cnblogs.com/YangFuShun/p/6703469.html