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 ...
随机推荐
- 让Android中的webview支持页面中的文件上传
android webview在默认情况下是不支持网页中的文件上传功能的: 如果在网页中有<input type="file" />,在android webview中 ...
- 框架基础JNI
转载请标明出处: http://blog.csdn.net/yujun411522/article/details/46342793 本文出自:[yujun411522的博客] 2.1 概述 JNI ...
- Floodlight 处理交换机增加/移除过程
Floodlight 使用的是Netty架构,在Controller.java 入口函数中显示创建ServerBootstrap,设置套接字选项,ChannelPipeline,此时监听套接 ...
- 14.3.2.2 autocommit, Commit, and Rollback 自动提交 提交和回滚
14.3.2.2 autocommit, Commit, and Rollback 自动提交 提交和回滚 如果自动提交模式被启用,在InnoDB里, 所有的用户活动发生在一个事务里, 每个SQL语句 ...
- Bootstrapping (compilers) - Wikipedia, the free encyclopedia
Bootstrapping (compilers) - Wikipedia, the free encyclopedia Bootstrapping (compilers)
- poj 1611 The Suspects(并查集)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 21598 Accepted: 10461 De ...
- Oracle的dbms_output包的put()和put_line()的区别只是有没有回车换行吗?(转)
答案是否 除了自动添加回车换行外,还有就是缓冲区最大容量的问题!! 无论如何设置serveroutput size,10g里 put() 最多只能输出 32767 个byte 而 put_line() ...
- IOS中的id与nil
1 id id和void *并非完全一样.在上面的代码中,id是指向struct objc_object的一个指针,这个意思基本上是说,id是一个指向任何一个继承了Object(或者NSObject) ...
- Hawk-数据抓取工具
Hawk-数据抓取工具:简明教程 Hawk: Advanced Crawler& ETL tool written in C#/WPF 1.软件介绍 HAWK是一种数据采集和清洗工具,依据 ...
- JavaScript 中的事件类型4(读书笔记思维导图)
Web 浏览器中可能发生的事件有很多类型.如前所述,不同的事件类型具有不同的信息,而“ DOM3级事件”规定了以下几类事件. UI(User Interface,用户界面)事件:当用户与页面上的元素交 ...