一、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设备定位的更多相关文章

  1. iOS设备定位服务开启判定

    应用CLLocationManager 的两个方法 [CLLocationManagerlocationServicesEnabled] 判断设备是否开启定位功能 [CLLocationManager ...

  2. iOS 设备定位功能可用的判断

    if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] ...

  3. iOS地图 -- 定位初使用

    iOS的定位服务用到的框架是#import <CoreLocation/CoreLocation.h> 定位中用到的类是CLLocationManager 一.iOS8.0之前的定位 向用 ...

  4. iOS后台定位实现

    iOS后台定位实现 (2013-01-24 16:43:12)     工作中碰到一个定位的应用场景:app需要在后台运行,实时上传用户地理位置.   苹果对iOS的规范性在提升了app的品质的同时也 ...

  5. IOS设备对position的支持性

    最近在开发一个网页. 要嵌套在微信里 大家都知道 IOS版微信和安卓版微信还是一定的差距 IOS版微信在打开网页的时候回调取自己的浏览器以及内核 但是安卓版微信不会,他会默认使用自己的QQ浏览器和X5 ...

  6. iOS学习——获取iOS设备的各种信息

    不管是在Android开发还是iOS开发过程中,有时候我们需要经常根据设备的一些状态或信息进行不同的设置和性能配置,例如横竖屏切换时,电池电量低时,内存不够时,网络切换时等等,我们在这时候需要进行一些 ...

  7. ios设备触发虚拟键盘输入后position:fixed 无效的一些简单另类的解决方法。

    首先看一下我要解决的问题,第一张图是正常的情况下,第二张图是点击了输入框之后的情况,就是要解决此问题~! 百度了一下解决方法,好像有以下的一些方法: 1. iscroll 2. Jquery Mobi ...

  8. IOS设备 UIDevice 获取操作系统 版本 电量 临近手机触发消息检测 (真机亲测可用)

    - (void)viewDidLoad { [super viewDidLoad]; // 操作系统 NSString * osName =[[UIDevice currentDevice]syste ...

  9. 使用Safari远程调试iOS设备网页

    最近在做HTML 5游戏时,发布到手机上访问网页总是莫名其妙出现问题,苦于没有remote debug功能一直没有查找到问题. 这边博客详细介绍了iOS, Android, Windows Phone ...

随机推荐

  1. Swift - 使用EventKit获取系统日历事件,添加事件

    通过EventKit可以对iOS日历事件进行读取,添加等操作.但网上找到的都是使用Objective-C来编写的. 下面提供一个Swift版的样例,演示如何添加一个事件以及获取所有的事件列表. 1 2 ...

  2. maven项目配置Project Facets时further configuration available不出来问题

    如果下边的 further configuration available不出来 把Dynamic web module 去掉勾选,应用与项目,然后再点开项目的properties,再选中Dynami ...

  3. uva 1151 - Buy or Build poj 2784 Buy or Build(最小生成树)

    最小生成树算法简单 只是增加了一些新的东西,对于需要最小生成树算法 和中 并检查使用的一系列 还有一些更深入的了解. 方法的一些复杂问题 #include<cstdio> #include ...

  4. codeforces 598A Tricky Sum

    题目链接:http://codeforces.com/contest/598/problem/A 题目分类:大数 题意:1到n 如果是2的次方则减去这个数,否则就加上这个数,求最后的结果是多少 题目分 ...

  5. grep与正则表达式,grep、egrep和fgrep

    grep用法详解:grep与正则表达式 首先要记住的是: 正则表达式与通配符不一样,它们表示的含义并不相同!正则表达式只是一种表示法,只要工具支持这种表示法, 那么该工具就可以处理正则表达式的字符串. ...

  6. HDU 4616 Game (搜索)、(树形dp)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4616 这道题目数据可能比较弱,搜索都可以AC,但是不敢写,哎…… 搜索AC代码: #include & ...

  7. 用N2N搭建简单的VPN

    1.   概述 N2N是一款开源的P2P VPN软件,其作者是著名的开源网管软件ntop的作者Luca Deri. N2N是一个双层架构的VPN,它让用户能够在网络层上开发P2P应用的典型功能,而不是 ...

  8. JavaScript2谁刚开始学习应该知道4最佳实践文章(翻译)

    原版的:24 JavaScript Best Practices for Beginners (注:阅读原文的时候没有注意公布日期,觉得不错就翻译了,翻译到JSON.parse那一节觉得有点不正确路才 ...

  9. ActionBar本部分适用述评

    http://note.youdao.com/share/?id=7f213cb64069bad221f4581507707294&type=note 因为把图片拿进来太麻烦,所以我给了一个直 ...

  10. 基于WEB 的认证防火墙的设计

    项目要求: 1.  采用Linux iptbles作为接入防火墙,默认放行所以访问入口的80端口 2.  访问者通过http://x.x.x.x 访问防火墙的认证系统,进行账号的登陆操作,同时系统对用 ...