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 ...
随机推荐
- Java经典面试题及详解
Java基础方面: 1.作用域public,private,protected,以及不写时的区别 答:区别如下: 作用域 当前类 同一package ...
- iOS视图控制器之间delegate传值教程
之前在StackOverFlow上看到一篇讲传值(segue传值和delegate传值)的文章,感觉讲的非常清晰,就将delegate部分翻译了一下.有兴趣能够看看. 原文: http://stack ...
- Struts2他们拦截器实例定义—登陆权限验证
版本号:struts2.1.6 这种情况下实现功能:用户需要指定username登陆,进入相应的页面运行成功登陆作战,否则,它返回到着陆的登录页面,当直接进入操作页面(登陆访问页面后的能力)如果不同意 ...
- Java按钮设计
package com.han; import javafx.application.Application; import javafx.geometry.Insets; import javafx ...
- HttpGet协议与正则表达
使用HttpGet协议与正则表达实现桌面版的糗事百科 写在前面 最近在重温asp.net,找了一本相关的书籍.本书在第一章就讲了,在不使用浏览器的情况下生成一个web请求,获取服务器返回的内容.于 ...
- 浅谈 PHP 变量可用字符
原文:浅谈 PHP 变量可用字符 先来说说php变量的命名规则,百度下一抓一大把:(1) PHP的变量名区分大小写;(2) 变量名必须以美元符号$开始;(3) 变量名开头可以以下划线开始;(4) 变量 ...
- HDU 4814 Golden Radio Base 模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 题目大意: 把一个正整数表示为φ进制, φ = (1+√5)/2 . 且已知: 1. φ + 1 ...
- Java中的工具类和新特性
1:Collections集合框架工具类: /* 集合框架的工具类. Collections:集合框架的工具类.里面定义的都是静态方法. Collections和Collection有什么差别? Co ...
- 【WinRT】【译】【加工】在 XAML 中制作圆形图片
原文:[WinRT][译][加工]在 XAML 中制作圆形图片 原文地址:http://timheuer.com/blog/archive/2015/05/06/making-circular-ima ...
- s nrmtyu,yi.sfn rt
http://www.zhihu.com/collection/24337307 http://www.zhihu.com/collection/24337259 http://www.zhihu.c ...