//获取位置和坐标
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
        if (IOS_VERSION >= 8.0) {
            //由于IOS8中定位的授权机制改变 需要进行手动授权
            //获取授权认证
            [locationManager requestAlwaysAuthorization];
            [locationManager requestWhenInUseAuthorization];
        }
#else
#endif
        if ([CLLocationManager locationServicesEnabled] == YES) {
            [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
            [locationManager setDistanceFilter:kCLDistanceFilterNone];
            [locationManager startUpdatingLocation];
        } else {
            [self clearLocation];
        }

#pragma mark CLLocationManagerDelegate Method

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    debugLog(@"获取到定位信息");
    CLLocation *cllocation = [locations objectAtIndex:0];
    NSString *longtitudeStr = [NSString stringWithFormat:@"%f", cllocation.coordinate.longitude];
    NSString *latitudeStr = [NSString stringWithFormat:@"%f", cllocation.coordinate.latitude];
    [manager stopUpdatingLocation];
    
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:cllocation completionHandler:^(NSArray *placemarks, NSError *error) {
        if (error == nil) {
            if ([Common isEmptyArray:placemarks] == NO) {
                CLPlacemark *placemark = [placemarks objectAtIndex:0];
                NSString *administrativeArea = placemark.administrativeArea;
                NSString *city = placemark.locality;
                NSString *subLocality = placemark.subLocality;
                NSString *thoroughfare = placemark.thoroughfare;
                if ([Common isEmptyString:administrativeArea] == YES) {
                    administrativeArea = @"";
                }
                if ([Common isEmptyString:city] == YES) {
                    city = @"";
                }
                if ([Common isEmptyString:subLocality] == YES) {
                    subLocality = @"";
                }
                if ([Common isEmptyString:thoroughfare] == YES) {
                    thoroughfare = @"";
                }
                NSString *locationStr = [administrativeArea stringByAppendingString:city];
                locationStr = [locationStr stringByAppendingString:subLocality];
                locationStr = [locationStr stringByAppendingString:thoroughfare];
                
                [self updateLongtitude:longtitudeStr];
                [self updateLatitude:latitudeStr];
                [self updateLocation:locationStr];
            } else {
                [self clearLocation];
            }
        } else {
            debugLog(@"获取定位信息失败, 失败原因 = %@", error.localizedDescription);
            [self clearLocation];
        }
        [manager setDelegate:nil];
    }];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    debugLog(@"获取定位信息失败, 失败原因 = %@", error.localizedDescription);
    [self clearLocation];
}

IOS CLLocationManager定位反编码位置信息的更多相关文章

  1. android GPS 定位,取位置信息

    现在很多app ,需要取位置信息,所以我也做了一个模块用来取位置信息:   加入位置服务所需的权限: <uses-permission android:name="android.pe ...

  2. 定位 - CoreLocation - 打印位置信息

    1. 导入框架 <CoreLocation.framework>, 引入头文件 import <CoreLocation/CoreLocation.h>; 2. 创建管理者对象 ...

  3. iOS CLLocationManager定位

    本文转载至 http://www.tuicool.com/articles/7JBRZn 在iOS8以前的版本中,我们使用CLLocationManager定位是没有问题的,最近在iOS8系统中却无法 ...

  4. iOS 定位于地理反编码

    - (void)viewDidLoad { [self startLocation]; } //开始定位 -(void)startLocation{ self.locationManager = [[ ...

  5. Android 集成GoogleMap,实现定位和获取位置信息

    1.准备 我使用的是AS2.2.2,首先FQ注册google开发者帐号,准备获取API Key,网上有许多相关资料我就不再赘述,这里讲一个比较小白级的获取方法,可以减少许多输入 1.1. AS创建项目 ...

  6. ios 定位获取当前位置信息

    啊,倦怠的人生啊~~ 什么事情都没做一眨眼就2点半了啊!!赶紧爬起来写博客啊. 诸位看官会鄙视我么,表示我真心不是把这当技术文章写的啊. 啊,下午我们来第二篇.获取地理位置信息.嗯嗯,秘籍上说叫逆向地 ...

  7. iOS CLLocationManager 定位

    今天写个定位,本来很简单,但是在填写plist时,通过系统提示,只能看到NSLocationUsageDescription项目,根本不提示 (1)NSLocationAlwaysUsageDescr ...

  8. iOS开发----地图与导航--定位和位置信息获取

    要实现地图.导航功能,往往需要先熟悉定位功能,在iOS中通过Core Location框架进行定位操作.Core Location自身可以单独使用,和地图开发框架MapKit完全是独立的,但是往往地图 ...

  9. iOS定位和位置信息获取

    要实现地图.导航功能,往往需要先熟悉定位功能,在iOS中通过Core Location框架进行定位操作.Core Location自身可以单独使用,和地图开发框架MapKit完全是独立的,但是往往地图 ...

随机推荐

  1. IT项目管理

    IT项目管理是项目管理在IT领域的应用,结合IT行业特点运用项目管理技术.理念和方法,包括9大知识领域(项目综合.范围.时间.成本.质量.人力资源.沟通.风险和采购管理)以及启动.计划.实施.控制和收 ...

  2. [Flex] ButtonBar系列——flex3 labelFunction用户提供的函数,在每个项目上运行以确定其标签

    <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="h ...

  3. CRM plugin 激活 停用 事件

    需要注册 SetState 和 SetStateDynamecEntity

  4. java异常处理机制throws

    throws可以在方法声明时抛出的异常.原则上throws声明的异常,一定要在该方法中抛出,否则没有意义. 相反的,若方法中我们主动通过throw抛出一个异常,应该在throws中声明该种类异常,通知 ...

  5. zabbix 修改输出web前端图片的日期格式

    zabbix并没有给定一个全局或者用户级别的时间格式定义方式. 实在看不惯的话,可以自己修改源代码来实现修改. 暂时研究了半小时,先把展示图片修改了. 后续有更严谨的方案,再更新此文吧. ------ ...

  6. Droid VNC Server

    这个app可以在Android开启VNC Server,让其他的VNC Client远程连接手机,不过前提是要ROOT.哎,可惜了. 当然还有另一款替代品Total Control http://ww ...

  7. Selenium 疑问之二:如何使页面滚动条移动到指定元素element的位置处?

    在用selenium做测试时,会遇到需要操作的元素不在当前可视页面中的情况,如果是手工测试,自然很简单,手动拖拽滚动条到目标元素处即可. 那么,selenium如何实现这种情形呢?答案是需要借助Jav ...

  8. 黑马程序员_Java基本数据的自动拆装箱及享元设计模式视频学习笔记

    ------- android培训.java培训.期待与您交流! ---------- 装箱:把基本数据类型装成java类(被托管?).         拆箱:把java类拆成基本数据类型(取消托管? ...

  9. JQuery基础教程:事件(上)

    在页面加载后执行任务      之前我们已经知道了$(document).ready()是jQuery基于页面加载执行任务的一种主要方式,但是要知道原生的window.onload事件也可以实现相同的 ...

  10. FPS学习记录

    最近在网上查了一些FPS的相关知识,在此和大家一起分享.FPS(Frames Per Second):每秒传输帧数,它是图像领域中的一个术语. Frames Per Second更确切的解释是“每秒中 ...