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

                

            }

        }

    }];

    

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM