//获取位置和坐标
#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. Redis中7种集合类型应用场景&redis常用命令

    Redis常用数据类型 Redis最为常用的数据类型主要有以下五种: String Hash List Set Sorted set 在具体描述这几种数据类型之前,我们先通过一张图了解下Redis内部 ...

  2. CSS学习笔记之定位

    position 有4中不同类型的定位,分别为static.relative.absolute.fixed 1.static 元素框正常生成.块级元素生成一个矩形框,作为文档流的一部分,行内元素则会创 ...

  3. java多线程的使用2

    1.join与interrupt的用法 class Sleeper extends Thread { private int duration; public Sleeper(String name, ...

  4. 在VMware虚拟机中配置DOS汇编开发环境!!

    操作系统:win7 32位 DOS环境:DosBox  下载:http://www.dosbox.com/ 选择当前适合自己版本,下载就可以了. 汇编编译器:MASM 5.0 下载:http://do ...

  5. angularJs中的隐藏和显示

    <!DOCTYPE html> <html ng-app="a2_12"> <head> <meta charset="utf- ...

  6. SELinux配置不当导致httpd无法在非80端口启动

    检测是否为selinux导致httpd启动失败,若setenforce 0以后就可以启动,就表示selinux配置不当. 首先本机要支持semanage命令,安装方法网上有. semanage  po ...

  7. (DP)MaxSubArr

    public static int MSA(int[] ar) { int[] arr = new int[ar.length]; int msa = 0; arr[0] = ar[0]; for ( ...

  8. 使用jaxp对比xml进行DOM解析

    /*DOM解析编程 •遍历所有节点 •查找某一个节点 •删除结点 •更新结点 •添加节点 /* package cn.itcast.jaxp; import java.io.File; import ...

  9. 浅谈Java的包装类

    一.什么是Java包装类 所谓Java包装类,就是将Java中的8种基本数据类型分别包装成为类的形式.包装类与基本数据类型的对应关系如下表所示. 基本数据类型 包装类 byte Byte short ...

  10. 多媒体编程基础之RGB和YUV

    一.概念 1.什么是RGB? 对一种颜色进行编码的方法统称为“颜色空间”或“色域”.用最简单的话说,世界上任何一种颜色的“颜色空间”都可定义成一个固定的数字或变量.RGB(红.绿.蓝)只是众多颜色空间 ...