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



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

AD

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

1、位置管理器

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

2、位置管理器代理

主要的代理方法有两个

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

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


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值