iOS 定位于地理反编码
- (void)viewDidLoad { [self startLocation];
} //开始定位
-(void)startLocation{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self; [self.locationManager requestWhenInUseAuthorization];
if ([[[UIDevice currentDevice]systemVersion]doubleValue]>=8.0) { [self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestAlwaysAuthorization]; }
[self.locationManager startUpdatingLocation]; if ([CLLocationManager locationServicesEnabled]) {
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
}else
{
NSLog(@"open fail");
} }
#pragma mark - CoreLocation 代理
#pragma mark 跟踪定位代理方法,每次位置发生变化即会执行(只要定位到相应位置)
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *location=[locations lastObject];
CLLocationCoordinate2D coordinate=location.coordinate;
NSLog(@"经度:%f,纬度:%f",coordinate.longitude,coordinate.latitude);
self.longitude=coordinate.longitude;
self.latitude=coordinate.latitude;
//如果不需要实时定位,使用完即使关闭定位服务
[self.locationManager stopUpdatingLocation];
[self weiZhi];
}
-(void)weiZhi
{
self.geocoder=[[CLGeocoder alloc]init];
CLLocation *rr=[[CLLocation alloc]initWithLatitude:self.latitude longitude:self.longitude];
[self.geocoder reverseGeocodeLocation:rr completionHandler:^(NSArray *placemarks, NSError *error) { CLPlacemark *mark=[placemarks objectAtIndex:];
UILabel *currentLocation=[[UILabel alloc]initWithFrame:CGRectMake(, , , )];
currentLocation.text=[NSString stringWithFormat:@"%@",mark.subLocality]; [self.locationView addSubview:currentLocation];
}]; }
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
switch (status) {
case kCLAuthorizationStatusNotDetermined:
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[self.locationManager requestWhenInUseAuthorization];
}
break;
default:
break;
} }
//当定位出现错误时就会调用这个方法。
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(@"error-%@",error); }
定位当前的位置。对于 CLPlacemark 还有许多属性,不仅仅可以给出当前位置,还可以给出其他信息,后续研究。。。。
iOS 定位于地理反编码的更多相关文章
- IOS CLLocationManager定位反编码位置信息
//获取位置和坐标#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1 if (IOS_VERSION >= 8.0) { ...
- 猫猫学iOS 之CoreLocation反地理编码小Demo输入经纬度得到城市
猫猫分享,必须精品 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243 一:效果 输入经纬度,能够得到相应的地名 二:思路 跟地里编码差 ...
- iOS地理反地理编码--CoreLocation
.sidebar{float:left;width:220px;} .container-fluid>.content{margin-left:240px;} a{color:#0069d6;t ...
- AJ学IOS 之CoreLocation反地理编码小Demo输入经纬度得到城市
AJ分享,必须精品 一:效果 输入经纬度,可以得到相应的地名 二:思路 跟地里编码差不多 1.获取用户输入的经纬度 2.根据用户输入的经纬度创建CLLocation对象 3.根据CLLocation对 ...
- iOS - GeoCoder 地理编码
前言 NS_CLASS_AVAILABLE(10_8, 5_0) @interface CLGeocoder : NSObject 地理编码 地名 -> 经纬度 等具体位置数据信息.根据给定的位 ...
- 定位- CLGeoencoder - 反编码
#import "ViewController.h" #import "MBProgressHUD+MJ.h" #import <CoreLocation ...
- 地图定位CoreLocation框架,地理位置编码与反编码
在现代互联网时代,越来越多的应用,都用到了地图定位功能,在iOS开发中,想要加入这种功能,必须基于两个框架进行开发: 1.Map Kit:用于显示地图, 2.CoreLocation:用于显示地理位置 ...
- 使用多字节字符集的跨平台(PC、Android、IOS、WP)编码/解码方法
随着移动端的发展,跨平台已成为通讯架构设计的重要考虑因素,PC.Android.IOS.WP等跨多平台间的数据通讯,必然要解决字符编码/解码的问题. 多字节字符集MBCS不是跨平台的首选字符集,面向跨 ...
- 使用apache-commons-lang3架构对HTML内容进行编码和反编码
String a="<br>"; String a_str=StringEscapeUtils.escapeHtml4(a);//编码 System.out.print ...
随机推荐
- web组件
慕课网:http://www.imooc.com/learn/99 js 在实战中的分层: 应用层 框架组件-框架通用组件.定制组件.独立组件 框架core(框架核心层) 浏览器底层
- 整理一下以前的Html+css3复习笔记
一.html5新特性 常用语义标签:nav footer header section mark 功能标签 video audio iframe canvas(画布和绘图功能) input新ty ...
- python访问数据库一
直接访问mysql,示例如下: # coding:utf-8 import time import MySQLdb # import traceback # import sys conn = MyS ...
- osg,vtk,ogre的区别
osg使用过一年,阅读过一部分源代码,vtk也断续使用过三四年了,ogre研究的比较深入,基本上比较熟悉它的整体结构,说说个人的看法 vtk是一个算法库,里面包括了很多挺不错的算法,如果做有限元云图, ...
- JQuery 对 Select option 的操作
下拉框: <select id="selectID" > <option value="1">1</option& ...
- log4net.NoSql +ElasticSearch 实现日志记录
前言: 前两天在查找如何扩展log4net的日志格式时找到一个开源项目Log4net.NoSql,它通过扩展Appender实现了把日志输出到ElasticSearch里面.顺藤摸瓜,发现涉及的项目还 ...
- ionic本质
ionic本质一开发工具,ionic项目目录里在大堆东西,一堆插件(plugins),还有一堆npm包(node_modules),其实都是骗人的-( ̄▽ ̄-)~ 什么nodejs,npm只是为了解决 ...
- sql like in 语句获取以逗号分割的字段内的数据
From:http://www.cnblogs.com/goody9807/archive/2011/07/27/2118107.html sql中的某个字段用“,”分隔数据,需要获取数据的时候直接把 ...
- Linux驱动之HelloWorld
最近看android的一些源码,里面有一些功能是用驱动实现的.于是就兴起看了一些驱动相关的东西,准备日后深入.这没有技术含量的水文,仅作为日后的备忘吧. 系统使用的是ubuntu 12.0.04,内核 ...
- android 定时器AlarmManager
1.android中通常是使用AlarmManager来定时启动一个单次或重复多次操作的.具体的说就是我们通过AlarmManager设定一个时间和注册一个intent到系统中,然后在该时间到来时,系 ...