//获取位置和坐标
#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. Android应用框架浅析

    http://blog.csdn.net/yanbober/article/category/3206943 Android应用层View绘制流程与源码分析   http://blog.csdn.ne ...

  2. C++学习25 纯虚函数和抽象类

    在C++中,可以将成员函数声明为纯虚函数,语法格式为: ; 纯虚函数没有函数体,只有函数声明,在虚函数声明结尾加上=0,表明此函数为纯虚函数. 最后的=0并不表示函数返回值为0,它只起形式上的作用,告 ...

  3. java异常处理机制throw

  4. ORACLE directory 目录--转载

    Create directory让我们可以在Oracle数据库中灵活的对文件进行读写操作,极大的提高了Oracle的易用性和可扩展性.其语法为:CREATE [OR REPLACE] DIRECTOR ...

  5. C++编译错误syntax error : identifier 'THIS_FILE' 解决方法

    你到代码里搜索 THIS_FILE看是不是它定义在别的头文件前面了,如果是,把它们的头文件紧跟到Stdafx.h后面 我遇到过这问题,这样搞定的 今天遇到个编译错误:..\vc98\include\n ...

  6. 【转】WEB测试到移动测试的转换

    移动互联网的发展毋庸置疑是必然的趋势,我们曾经传统WEB互联网测试的同学,也必然走上移动测试的道路,移动测试与pc测试到底需要怎样的思维转变才能更快的进入移动节奏呢?对比下WEB与移动的测试不同点: ...

  7. Android开发-API指南-<category>

    <category> 英文原文:http://developer.android.com/guide/topics/manifest/category-element.html 采集(更新 ...

  8. SDUT 3345 数据结构实验之二叉树六:哈夫曼编码

    数据结构实验之二叉树六:哈夫曼编码 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 字符的编 ...

  9. MySQL(二)

    一.外键 外键是设置当前表中的某一列与别一数据表中的主键列关联.主要目的是控制与外键表中的数据,保持数据一致性,完整性,也就是说:当前表中这一列的数据必须是关联外键列中的某一数据,而且相关联的两个数据 ...

  10. word2010忽然无法撤销

    转:http://tieba.baidu.com/p/1115124288     第三楼 关闭正在运行的所有程序. 按Win-R,在运行框中键入regedit,然后单击“确定”. 在注册表编辑器中, ...