首页 > 移动平台 > 详细

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

时间:2017-04-13 13:37:40      阅读:482      评论:0      收藏:0      [点我收藏+]

 

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

                

            }

        }

    }];

    

}

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

原文:http://www.cnblogs.com/YangFuShun/p/6703469.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!