//获取位置和坐标
#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. ubuntu 关机,重启,注销命令

    1关机命令 shutdown 好像ubuntu的终端中默认的是当前用户的命令,只是普通用户,因此在终端器中可以使用sudo -sh 转换到管理员root用户下执行命令. 1)shutdown –hel ...

  2. 解决dedev5.7更新出现include\userlogin.class.php on line 21的办法

    第一种情况解决办法:   在dede\templets文件夹 找到 index_body.htm  文件 把这些注释掉. $(function() {    $.get("index_tes ...

  3. 中文系统下,UTF-8编码文本文件读取导致的错误

    一.UTF-8编码文件读取导致的错误 有个txt文件,里面内容为: aaa bbb ccc 以UTF-8编码方式打开txt文件,顺序读取,将里面的值放到一个hashset中,并判断aaa是否在在has ...

  4. 理论沉淀:隐马尔可夫模型(Hidden Markov Model, HMM)

    理论沉淀:隐马尔可夫模型(Hidden Markov Model, HMM) 参考链接:http://www.zhihu.com/question/20962240 参考链接:http://blog. ...

  5. [kuangbin带你飞]专题十二 基础DP1

            ID Origin Title   167 / 465 Problem A HDU 1024 Max Sum Plus Plus   234 / 372 Problem B HDU 1 ...

  6. C Primer Plus(第五版)11

    第 11 章 字符串和字符串函数 在本章中你将学习下列内容: · 函数: gets(), puts(), strcat(), strncat(), strcmp(), strncmp(), strcp ...

  7. CodeForces 604D 【离散数学 置换群】

    题意: 给你一个方程,方程太变态不打,给你一个p一个k,p保证是大于等于3的质数,k保证在0~p-1之间的整数.要求对应函数的定义域在0~p-1值域为0~p-1的子集,求这样的函数有多少个... 分析 ...

  8. nyoj 61 传纸条

    点击打开链接 传纸条(一) 时间限制:2000 ms  |  内存限制:65535 KB 难度:5 描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做 ...

  9. UIPickView 和 UIDatePicker

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  10. 在 WPF 程序中使用 MVVM 模式

    MVVM 模式是一个很久之前的技术了,最近因为一个项目的原因,需要使用 WPF 技术,所以,重新翻出来从前的一段程序,重温一下当年的技术. MVVM 模式 MVVM 实际上涉及三个部分,Model, ...