iPhone开发应用中CoreLocation定位学习笔记

移动开发 iOS
本文介绍的是iPhone开发应用中CoreLocation定位的内容,iPhone可以使用CoreLocation框架确定他的物理位置,可以利用三种技术来实现该功能:GPS,WiFi定位和蜂窝基站三角网定位。

iPhone开发应用中CoreLocation定位学习是本文要介绍的内容,iPhone可以使用CoreLocation框架确定他的物理位置,可以利用三种技术来实现该功能:GPS,WiFi定位和蜂窝基站三角网定位。但在程序中我们只需设定我们希望的精度级别,由CoreLocation决定采用哪种技术可以更好的满足我们的请求。

1、位置管理器

  1. CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器  
  2. locationManager.delegate=self;//设置代理  
  3. locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别  
  4. locationManager.distanceFilter=1000.0f;//设置距离筛选器  
  5. [locationManager startUpdatingLocation];//启动位置管理器 

2、位置管理器代理

主要的代理方法有两个

  1. //确定当前位置和位置更新了时调用这个方法  
  2.  
  3. - (void)locationManager:(CLLocationManager *)manager  
  4. didUpdateToLocation:(CLLocation *)newLocation  
  5.    fromLocation:(CLLocation *)oldLocation  
  6. {  
  7. NSString *latitudeString=[[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.latitude];  
  8. //latitudeLabel.text=latitudeString;  
  9. [latitudeString release];  
  10. NSString *longitudeString=[[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.longitude];  
  11. //longitudeLabel.text=longitudeString;  
  12. [longitudeString release];  
  13. }  
  14. //位置查询遇到错误时调用这个方法  
  15.  
  16.  (void)locationManager:(CLLocationManager *)manager  
  17.   didFailWithError:(NSError *)error  
  18. {  
  19. NSString *errorType = (error.code == kCLErrorDenied) ?  
  20.    @"Access Denied" : @"Unknown Error";  
  21.    UIAlertView *alert = [[UIAlertView alloc]  
  22.                          initWithTitle:@"Error getting Location"  
  23.                           message:errorType  
  24.                           delegate:nil  
  25.                           cancelButtonTitle:@"Okay"  
  26.                           otherButtonTitles:nil];  
  27.     [alert show];  
  28.     [alert release];  

小结:iPhone开发应用中CoreLocation定位学习笔记的内容介绍完了,希望本文对你有所帮助。

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-08-09 17:29:29

iPhone文件屏幕

2011-08-08 14:57:46

iPhone Autoreleas Property

2011-08-19 11:10:31

iPhone应用

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-15 10:06:22

iPhone开发nib 文件

2011-08-08 10:10:14

iPhone开发 图片 方法

2011-08-18 10:39:46

iPhone开发界面

2011-08-05 14:48:06

iPhone应用 异步队列

2011-08-08 15:56:18

iPhone 震动 NSUserDefa

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-15 17:38:48

iPhone开发调试工具

2011-07-27 11:14:37

iPhone UITableVie

2011-08-09 14:42:07

iPhonePCM播放器

2011-08-15 15:44:46

iPhone开发PDF

2011-08-12 14:33:06

iPhone缓存文件

2011-08-18 16:24:44

iPhone开发图片

2011-08-15 17:52:21

iPhone应用对象NSString

2011-08-15 18:02:32

iPhone开发表视图

2011-08-22 14:12:48

iPhone开发NSTableView

2011-08-15 11:37:20

iPhone开发Mask
点赞
收藏

51CTO技术栈公众号