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

来源:互联网 发布:嫁给外国人 知乎 编辑:程序博客网 时间:2024/06/05 16:06



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

AD

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定位学习笔记的内容介绍完了,希望本文对你有所帮助。


from:http://mobile.51cto.com/iphone-282956.htm

原创粉丝点击