CoreLocation定位学习笔记
来源:互联网 发布:活蛆奶酪 知乎 编辑:程序博客网 时间:2024/05/29 11:49
一.基本知识
iPhone可以使用CoreLocation框架确定他的物理位置,可以利用三种技术来实现该功能:GPS,WiFi定位和蜂窝基站三角网定位。但在程序中我们只需设定我们希望的精度级别,由CoreLocation决定采用哪种技术可以更好的满足我们的请求。
二.具体介绍
1.位置管理器
CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器
locationManager.delegate=self;//设置代理
locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别
locationManager.distanceFilter=1000.0f;//设置距离筛选器
[locationManager startUpdatingLocation];//启动位置管理器
2.位置管理器代理
主要的代理方法有两个
//确定当前位置和位置更新了时调用这个方法
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSString *latitudeString=[[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.latitude];
//latitudeLabel.text=latitudeString;
[latitudeString release];
NSString *longitudeString=[[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.longitude];
//longitudeLabel.text=longitudeString;
[longitudeString release];
}
//位置查询遇到错误时调用这个方法
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSString *errorType = (error.code == kCLErrorDenied) ?
@"Access Denied" : @"Unknown Error";
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error getting Location"
message:errorType
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
[alert release];
}
iPhone可以使用CoreLocation框架确定他的物理位置,可以利用三种技术来实现该功能:GPS,WiFi定位和蜂窝基站三角网定位。但在程序中我们只需设定我们希望的精度级别,由CoreLocation决定采用哪种技术可以更好的满足我们的请求。
二.具体介绍
1.位置管理器
CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器
locationManager.delegate=self;//设置代理
locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别
locationManager.distanceFilter=1000.0f;//设置距离筛选器
[locationManager startUpdatingLocation];//启动位置管理器
2.位置管理器代理
主要的代理方法有两个
//确定当前位置和位置更新了时调用这个方法
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSString *latitudeString=[[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.latitude];
//latitudeLabel.text=latitudeString;
[latitudeString release];
NSString *longitudeString=[[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.longitude];
//longitudeLabel.text=longitudeString;
[longitudeString release];
}
//位置查询遇到错误时调用这个方法
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSString *errorType = (error.code == kCLErrorDenied) ?
@"Access Denied" : @"Unknown Error";
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error getting Location"
message:errorType
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
[alert release];
}
- CoreLocation定位学习笔记
- iOS学习笔记 地图(一)定位CoreLocation
- iPhone开发应用中CoreLocation定位学习笔记
- iOS学习笔记19-地图(一)定位CoreLocation
- 定位CoreLocation
- CoreLocation 定位
- CoreLocation定位
- iOS 定位 <CoreLocation/CoreLocation.h>
- 地图---CoreLocation框架(学习笔记)
- [iOS学习]关于定位的基础知识-CoreLocation框架
- IOS学习之——CoreLocation定位的使用
- iOS定位服务CoreLocation
- CoreLocation定位服务2
- iOS定位--CoreLocation
- CoreLocation定位服务
- CoreLocation定位服务
- CoreLocation框架定位详解
- iOS 使用CoreLocation定位
- "the currently displayed page contains invalid values"错误解决
- Ubuntu 11.10 无法获得锁 /var/lib/dpkg/lock解决办法
- IPFIX学习笔记
- 调试术语
- http://acm.nyist.net/JudgeOnline/problem.php?pid=32&&DFS
- CoreLocation定位学习笔记
- 当bug邂逅梦想,如何更好的debug
- 利用Visual Studio实现自动化测试
- ASP.NET获取IP的6种方法
- mplayer demux
- struts跳出iframe
- iPhone静态库学习笔记
- photoshop how to make rectangle pic to rounded rectangle pic
- conversation:in Good common