国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

iOS定位(一)地圖定位

2019-11-14 18:34:19
字體:
來源:轉載
供稿:網友
帶地圖的定位方法
#import
<CoreLocation/CoreLocation.h>#import <MapKit/MapKit.h><MKMapViewDelegate>//1.使用定位服務 //設置app有訪問定位服務的權限 //在使用應用期間 / 始終(app在后臺) //info.plist文件添加以下兩條(或者其中一條): 這句話非常重要,關系到你能不能定位 //NSLocationWhenInUseUsageDescription 在使用應用期間 //NSLocationAlwaysUsageDescription 始終 //2.LocationManager 對象管理相關的定位服務 _manager = [[CLLocationManager alloc] init]; //manager判斷: 手機是否開啟定位 / app是否有訪問定位的權限 //[CLLocationManager locationServicesEnabled]; //手機是否開啟定位 //[CLLocationManager authorizationStatus]; //app訪問定位的權限的狀態 if (![CLLocationManager locationServicesEnabled] || [CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedWhenInUse) { [_manager requestWhenInUseAuthorization]; //向用戶請求訪問定位服務的權限 }//3.地圖 [self createMapView];- (void)createMapView{ //創建MapView _mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; //地圖的類型 _mapView.mapType = MKMapTypeStandard; //顯示用戶當前的位置 //_mapView.userLocation //是否定位(是否追蹤用戶的位置) _mapView.userTrackingMode = MKUserTrackingModeFollow; _mapView.delegate = self; [self.view addSubview:_mapView];}//更新用戶的位置- (void)mapView:(MKMapView*)mapView didUpdateUserLocation:(MKUserLocation*)userLocation{ NSLog(@"location : %@", userLocation.location); //根據經緯度設置MapView //設置顯示的區域范圍, 設置顯示的精度 //設置顯示的精度(比例尺) MKCoordinateSpan span = MKCoordinateSpanMake(0.01, 0.01); //指定的范圍 MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.location.coordinate, span); //移動mapView顯示的位置 [_mapView setRegion:region animated:YES];}

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 元阳县| 安徽省| 庆元县| 砀山县| 静宁县| 四会市| 屏东县| 宣城市| 得荣县| 宜城市| 成都市| 密山市| 黄浦区| 涞水县| 绩溪县| 济源市| 阳新县| 航空| 丹东市| 济宁市| 曲阳县| 连平县| 弥勒县| 龙陵县| 金堂县| 陈巴尔虎旗| 筠连县| 紫阳县| 桃园县| 鹤壁市| 民权县| 桐城市| 沁水县| 垣曲县| 依安县| 上蔡县| 理塘县| 北辰区| 黎城县| 东海县| 石台县|