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 ...
随机推荐
- xp下Oracle数据库导入SQLServer数据库数据
Oracle数据库利用ODBC数据源.PLSQL Developer导入SQLServer数据库数据 操作: 建立数据源:控制面板→管理工具→数据源 (ODBC) 打开,界面如下: 点击添加,界面如下 ...
- ASP.NET Aries 开发框架
开源:ASP.NET Aries 开发框架 前言: 随着岁月的推进,不知不觉已在.NET这领域上战斗了十年了. 青春还没来得急好好感受,却已是步入健忘之秋的老人一枚了. 趁着还有点记忆,得赶紧把硬盘里 ...
- android studio下的NDK开发详解(一)
源地址:http://www.voidcn.com/blog/chengkaizone/article/p-5761016.html 好记性不如烂笔头,开始坚持写博客,学一点记一点,只为了生活更好. ...
- cape town
开普敦_百度百科 开普敦
- spice for openstack
nova.conf vnc_enabled=False [Spice] agent_enabled=True enabled=True html5proxy_base_url=http://x.x.x ...
- stm32 ARM中的RO、RW和ZI DATA
一直以来对于ARM体系中所描述的RO,RW和ZI数据存在似是而非的理解,这段时间对其仔细了解了一番,发现了一些规律,理解了一些以前书本上有的但是不理解的东西,我想应该有不少人也有和我同样的困惑,因此将 ...
- MySQL分区技术 (一)
4:MySQL 分区技术(是mysql 5.1以版本号后開始用->是甲骨文mysql技术团队维护人员以插件形式插入到mysql里面的技术) 眼下,针对海量数据的优化主要有2中方法: 1:大表拆成 ...
- Android内存管理
首先Android理机制相当复杂.想要讲清楚比較困难.其次对于绝大多数用户来说.仅仅关心内存够不够用,至于内存怎样管理的这样的技术细节,不是用户须要去考虑的,写这样一个专题有没有意义?毕竟我们是用手机 ...
- HDU1035深度搜索
/* HDU1035 意甲冠军: 给定一个字符矩阵,N S W E分别代表向上,下,剩下,进 模拟搜索,推断: 若能走出字符矩阵.则Yes,输出步数 若走不出矩阵,那么必然有圈存在,必然在矩阵中存在一 ...
- 使用HtmlAgilityPack批量抓取网页数据
原文:使用HtmlAgilityPack批量抓取网页数据 相关软件点击下载登录的处理.因为有些网页数据需要登陆后才能提取.这里要使用ieHTTPHeaders来提取登录时的提交信息.抓取网页 Htm ...