日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CLLocationManager 位置定位

發布時間:2025/4/16 编程问答 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CLLocationManager 位置定位 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第一步,新建一個singleView的空白工程,如果新建,這里不做贅述了。

第二步:因為地圖開發相關的framework:MapKit.frameworkCoreLocation.framework?至于如何添加,一般的ios相關博客都是有介紹。

? ?主界面的控制器?ViewController.h?文件中,我們啥也不做,.m文件中,我們需聲明一個?CLLocationManager* locationManager的屬性,我們讓其實現CLLocationManagerDelegate的協議,并覆寫其更新位置的方法,如下

?

1 #import?"ViewController.h"??

2 #import?<CoreLocation/CoreLocation.h>??

3 @interface?ViewController?()<CLLocationManagerDelegate>{??

4 ??????

5 }??

6 ??

7 @property?(nonatomic,retain)CLLocationManager*?locationManager;??

8 ??

9 @end??

10????? ??

11????? @implementation?ViewController??

12????? ??

13????? -(id)initWithNibName:(NSString?*)nibNameOrNil?bundle:(NSBundle?*)nibBundleOrNil??

14????? ??

15????? {??

16????? ????if?(self?=?[super?initWithNibName:nibNameOrNil?bundle:nibBundleOrNil])?{??

17????? ????????NSLog(@"nibName:??%@???bundle:?%@",nibBundleOrNil,nibBundleOrNil);??

18????? ????????_locationManager?=?[[CLLocationManager?alloc]?init];??

19????? ??????????

20????? ????}??

21????? ??????

22????? ????return??self;??

23????? }??

24????? ??

25????? -?(void)dealloc??

26????? {??

27????? ????self.locationManager?=?nil;??

28????? ????[super?dealloc];??

}??

29????? -?(void)viewDidLoad??

30????? {??

31????? ????[super?viewDidLoad];??

32????? ?????Do?any?additional?setup?after?loading?the?view,?typically?from?a?nib.??

33????? ????delegate??

34????? ????self.locationManager.delegate?=?self;??

35????? ????The?desired?location?accuracy.??

36????? ????self.locationManager.desiredAccuracy?=?kCLLocationAccuracyBest;??

37????? ????Specifies?the?minimum?update?distance?in?meters.??

38????? ??

39????? ????self.locationManager.distanceFilter?=?kCLDistanceFilterNone;??

40????? ??

41????? ????self.locationManager.purpose?=?@"To?provide?functionality?based?on?user's?current?location.";??

42????? ??

43????? ????[self.locationManager?startUpdatingLocation];??

44????? }??

45????? ??

46????? -?(void)locationManager:(CLLocationManager?*)manager?didChangeAuthorizationStatus:(CLAuthorizationStatus)status?{??

47????? ????NSLog(@"didChangeAuthorizationStatus---%u",status);??

48????? }??

49????? ??

50????? -?(void)locationManager:(CLLocationManager?*)manager?didFailWithError:(NSError?*)error{??

51????? ????NSLog(@"didChangeAuthorizationStatus----%@",error);??

52????? }??

53????? ??

54????? -?(void)locationManager:(CLLocationManager?*)manager?didUpdateToLocation:(CLLocation?*)newLocation?fromLocation:(CLLocation?*)oldLocation{??

55????? ????UIAlertView*?av?=?[[UIAlertView?alloc]?initWithTitle:@"update"?message:[NSString?stringWithFormat:@"didUpdateToLocation:??newLocation:?%@??old:%@",newLocation,oldLocation]?delegate:nil?cancelButtonTitle:@"cancel"?otherButtonTitles:@"ok",?nil?nil];??

56????? ????[av?show];??

57????? ????[av?release];??

}

轉載于:https://www.cnblogs.com/zhaozhongpeng/p/4867843.html

總結

以上是生活随笔為你收集整理的CLLocationManager 位置定位的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。