iOS设备定位
一、iOS谈到定位
1、SignInSignOutViewController.h
@interface SignInSignOutViewController : UIViewController<CLLocationManagerDelegate>{
CLLocationManager *_locationManager;
// 纬度
float _latitude;
// 经度
float _longitude;
}
@property (nonatomic,retain) CLLocationManager *locationManager;
@property (nonatomic) float latitude;
@property (nonatomic) float longitude;
@end
2、SignInSignOutViewController.m
#import "SignInSignOutViewController.h" @interface SignInSignOutViewController () @end @implementation SignInSignOutViewController
@synthesize locationManager = _locationManager;
@synthesize latitude = _latitude;
@synthesize longitude = _longitude; -(void)dealloc{ self.locationManager = nil;
[super dealloc];
} - (void)viewDidUnload
{
[super viewDidUnload];
self.locationManager = nil;
} - (void)viewDidLoad
{
[super viewDidLoad];
// 实例化一个位置管理器
CLLocationManager *cllocationManager = [[CLLocationManager alloc] init];
self.locationManager = cllocationManager;
[cllocationManager release];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
if(![CLLocationManager locationServicesEnabled]){
[GlobalApplication Alert:@"提示":@"请开启定位:设置 > 隐私 > 位置 > 定位服务"];
}else{
if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized) {
[GlobalApplication Alert:@"提示":@"定位失败,请开启定位:设置 > 隐私 > 位置 > 定位服务 下 XX应用"];
}
}
} #pragma mark - CLLocationManagerDelegate
#pragma mark - CLLocationManagerDelegate
// 地理位置发生改变时触发
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D cc,cc2;
// 获取经纬度
cc.longitude = newLocation.coordinate.longitude;
cc.latitude = newLocation.coordinate.latitude;
// ios坐标(google)转换为 百度坐标
cc2 = BMKCoorDictionaryDecode(BMKBaiduCoorForWgs84(cc));
self.longitude = cc2.longitude;
self.latitude = cc2.latitude;
// 停止位置更新
[manager stopUpdatingLocation];
} // 定位失误时触发
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSString *errorString;
[manager stopUpdatingLocation];
switch([error code]) {
case kCLErrorDenied:
errorString = @"定位失败,请开启定位:设置 > 隐私 > 位置 > 定位服务 下 XX应用";
//errorString = @"Access to Location Services denied by user";
break;
case kCLErrorLocationUnknown:
errorString = @"定位失败,位置数据不可用";
break;
default:
errorString = @"定位失败,未知错误";
break;
} [GlobalApplication Alert:@"定位":errorString];
}
二、百度地图定位(版本号2.1)
1、MainMenuViewController.h
@interface MainMenuViewController : UIViewController<BMKUserLocationDelegate> {
BMKUserLocation *_mapLocation;
// 纬度
float _latitude;
// 经度
float _longitude;
}
@property (nonatomic, retain) BMKUserLocation *mapLocation;
@property (nonatomic) float latitude;
@property (nonatomic) float longitude;
@end
2、MainMenuViewController.m
#import "MainMenuViewController.h"
@interface MainMenuViewController () @end @implementation MainMenuViewController
@synthesize mapLocation = _mapLocation;
@synthesize latitude = _latitude;
@synthesize longitude = _longitude; -(void)dealloc{
self.mapLocation = nil;
[super dealloc]; } - (void)viewDidUnload
{
[super viewDidUnload];
self.mapLocation = nil;
} - (void)viewDidLoad
{
[super viewDidLoad];
BMKUserLocation *bmkLocation = [[BMKUserLocation alloc] init];
bmkLocation.delegate = self;
self.mapLocation = bmkLocation;
[bmkLocation release];
[self.mapLocation startUserLocationService];
} #pragma mark - baidu map /**
*调用startUserLocationService定位成功后,会调用此函数
*@param userLoc 我的位置坐标
*/
- (void)viewDidGetLocatingUser:(CLLocationCoordinate2D)userLoc{
if (userLoc.longitude != 0 && userLoc.latitude != 0 ) {
self.longitude = userLoc.longitude;
self.latitude = userLoc.latitude;
[self.mapLocation stopUserLocationService];
}
}
iOS:xxx.151604,xx.170156(iOS採集的坐标)
baidu:xxx.162720,xx.174000 (百度转换的坐标)
方法二:
baidu:xxx.162716,xx.173980 (坐标百度收藏)
iOS设备定位的更多相关文章
- iOS设备定位服务开启判定
应用CLLocationManager 的两个方法 [CLLocationManagerlocationServicesEnabled] 判断设备是否开启定位功能 [CLLocationManager ...
- iOS 设备定位功能可用的判断
if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] ...
- iOS地图 -- 定位初使用
iOS的定位服务用到的框架是#import <CoreLocation/CoreLocation.h> 定位中用到的类是CLLocationManager 一.iOS8.0之前的定位 向用 ...
- iOS后台定位实现
iOS后台定位实现 (2013-01-24 16:43:12) 工作中碰到一个定位的应用场景:app需要在后台运行,实时上传用户地理位置. 苹果对iOS的规范性在提升了app的品质的同时也 ...
- IOS设备对position的支持性
最近在开发一个网页. 要嵌套在微信里 大家都知道 IOS版微信和安卓版微信还是一定的差距 IOS版微信在打开网页的时候回调取自己的浏览器以及内核 但是安卓版微信不会,他会默认使用自己的QQ浏览器和X5 ...
- iOS学习——获取iOS设备的各种信息
不管是在Android开发还是iOS开发过程中,有时候我们需要经常根据设备的一些状态或信息进行不同的设置和性能配置,例如横竖屏切换时,电池电量低时,内存不够时,网络切换时等等,我们在这时候需要进行一些 ...
- ios设备触发虚拟键盘输入后position:fixed 无效的一些简单另类的解决方法。
首先看一下我要解决的问题,第一张图是正常的情况下,第二张图是点击了输入框之后的情况,就是要解决此问题~! 百度了一下解决方法,好像有以下的一些方法: 1. iscroll 2. Jquery Mobi ...
- IOS设备 UIDevice 获取操作系统 版本 电量 临近手机触发消息检测 (真机亲测可用)
- (void)viewDidLoad { [super viewDidLoad]; // 操作系统 NSString * osName =[[UIDevice currentDevice]syste ...
- 使用Safari远程调试iOS设备网页
最近在做HTML 5游戏时,发布到手机上访问网页总是莫名其妙出现问题,苦于没有remote debug功能一直没有查找到问题. 这边博客详细介绍了iOS, Android, Windows Phone ...
随机推荐
- hadoop(六) - ZooKeeper安装与配置
一. ZooKeeper配置 1.使用winscp上传zk安装包 zookeeper-3.4.5.tar.gz 2.解压安装包tar -zxvf zookeeper-3.4.5.tar.gz -C / ...
- Php 解析XML文件
Php 解析XML文件 Php 解析XML文件,仅供学习參考!演示样例代码例如以下: <?php header("Content-type: text/html; charset=ut ...
- IT痴汉的工作现状16-职业发展
回首多年来的工作经历.发现自己的职业发展真是太平庸只是了.就像我的名字张伟,平淡无奇.而我,还是几年前刚入职模样的我,仍然像个涉世未深的矛头小子,相信技术能够改变世界.真是一入IT深似海,为伊消得人憔 ...
- js动态添加Div
利用JavaScript动态添加Div的方式有很多,在这次开发中有用到,就搜集了一下比较常用的. 一.在一个Div前添加Div <html> <body> <div id ...
- 事务不提交,也有可能写redo和数据文件
事务不提交,也有可能写redo和数据文件
- nginx 区分pc和mobile 到不同的404页面
if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry|vivo)') { set $mobile_request '1'; } ...
- PCI 总线学习笔记
转载请注明出处:http://blog.csdn.net/lg2lh/article/details/8042008 PCI的基本协议这里就不介绍了,由于一般的芯片协议都是集成好的,我仅仅须要大体了解 ...
- 调用ShellExecute需要头文件
调用ShellExecute需要头文件 #include "windows.h " #include "shellapi.h "
- Visual Studio 2008中FormatX源代码格式化插件
原地址:http://www.cr173.com/html/15492_1.html 我总是对组里的兄弟代码规范性近乎完美的要求,举个简单的例子: 1. 每个方法必须有注释,方法参数详细说明 2. ...
- NET实现的DDD、CQRS与微服务架构
WeText项目:一个基于.NET实现的DDD.CQRS与微服务架构的演示案例 最近出于工作需要,了解了一下微服务架构(Microservice Architecture,MSA).我经过两周业余时间 ...