zoukankan      html  css  js  c++  java
  • 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];

                    

                }

            }

        }];

        

    }

  • 相关阅读:
    修改大表结构注意事项
    短信猫 Mysql ODBC问题
    各互联网公司UDE分享
    MySQL 取分类后的前n条
    批处理当前日期
    Fixed Event Scheduler No data zero rows fetched, selected, or processed
    数据库设计注意事项
    本月,下一月, 上一月 的 1号, 最后一号
    自动化测试编程语言的选择
    QTP描述编程中使用正则表达式
  • 原文地址:https://www.cnblogs.com/YangFuShun/p/6703469.html
Copyright © 2011-2022 走看看