IOS CLLocationManager定位反编码位置信息
//获取位置和坐标
#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定位反编码位置信息的更多相关文章
- android GPS 定位,取位置信息
现在很多app ,需要取位置信息,所以我也做了一个模块用来取位置信息: 加入位置服务所需的权限: <uses-permission android:name="android.pe ...
- 定位 - CoreLocation - 打印位置信息
1. 导入框架 <CoreLocation.framework>, 引入头文件 import <CoreLocation/CoreLocation.h>; 2. 创建管理者对象 ...
- iOS CLLocationManager定位
本文转载至 http://www.tuicool.com/articles/7JBRZn 在iOS8以前的版本中,我们使用CLLocationManager定位是没有问题的,最近在iOS8系统中却无法 ...
- iOS 定位于地理反编码
- (void)viewDidLoad { [self startLocation]; } //开始定位 -(void)startLocation{ self.locationManager = [[ ...
- Android 集成GoogleMap,实现定位和获取位置信息
1.准备 我使用的是AS2.2.2,首先FQ注册google开发者帐号,准备获取API Key,网上有许多相关资料我就不再赘述,这里讲一个比较小白级的获取方法,可以减少许多输入 1.1. AS创建项目 ...
- ios 定位获取当前位置信息
啊,倦怠的人生啊~~ 什么事情都没做一眨眼就2点半了啊!!赶紧爬起来写博客啊. 诸位看官会鄙视我么,表示我真心不是把这当技术文章写的啊. 啊,下午我们来第二篇.获取地理位置信息.嗯嗯,秘籍上说叫逆向地 ...
- iOS CLLocationManager 定位
今天写个定位,本来很简单,但是在填写plist时,通过系统提示,只能看到NSLocationUsageDescription项目,根本不提示 (1)NSLocationAlwaysUsageDescr ...
- iOS开发----地图与导航--定位和位置信息获取
要实现地图.导航功能,往往需要先熟悉定位功能,在iOS中通过Core Location框架进行定位操作.Core Location自身可以单独使用,和地图开发框架MapKit完全是独立的,但是往往地图 ...
- iOS定位和位置信息获取
要实现地图.导航功能,往往需要先熟悉定位功能,在iOS中通过Core Location框架进行定位操作.Core Location自身可以单独使用,和地图开发框架MapKit完全是独立的,但是往往地图 ...
随机推荐
- [C语言](一)第一个Windows 32 API的窗口程序
#include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain( ...
- Undefined symbols for architecture i386:"_OBJC_CLASS_$_xx", referenced from: 解决方法
多个人共同操作同一个项目或拷贝项目时,经常会出现类似这样的问题: Undefined symbols for architecture i386: "_OBJC_CLASS_$_xx文件名& ...
- Android牟利之道(一)--界面嵌入有米广告
经过了一番折腾,忙忙碌碌了一下午,终于搞明白了Android软件界面嵌入广告的方法,以下我以嵌入有米广告为例小结一下: 我的新浪微博(wind瑞):http://weibo.com/tianrui19 ...
- SVN版本管理trunk及branch相关merge操作
先说说什么是branch.按照Subversion的说法,一个branch是某个development line(通常是主线也即trunk)的一个拷贝,见下图: branch存在的意义在于,在不干扰t ...
- 浅析JAVA_HOME,CLASSPATH和PATH的作用
1,设置JAVA_HOME: java的目录一.为了方便引用,比如,你JDK安装在C:\ProgramFiles\Java\jdk1.7.0目录里,则设置JAVA_HOME为该目录路径, 那么以后你 ...
- IE10修改select样式
一般我们针对webkit内核的,都使用-webkit-appearance来控制一些表单元素. 但是IE10如何来控制呢? select::-ms-expand{display:none;}
- ubuntu 14.10 安装 zabbix
在ubuntu 14.10 上部署 zabbix 2.x 基本软件包安装 既然是ubuntu系统,当然要用好apt-get神器. 参考教程 URL:http://blog.csdn.net/cloud ...
- C#实现程序自重启
方法1: System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); / ...
- Django: TemplateDoesNotExist at /admin/
最近用virtualenv 总出现 Django: TemplateDoesNotExist at /admin/的问题,报错TemplateDoesNotExist at /admin/admin/ ...
- SQL SERVER树型数据处理时,函数递归调用问题,查询根节点,子节点函数
/* 标题:查询指定节点及其所有子节点的函数 作者:爱新觉罗.毓华(十八年风雨,守得冰山雪莲花开) 时间:2008-05-12 地点:广东深圳 */ ) , pid ) , name )) ' , n ...