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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

CoreLocation MKMapView

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

高德開發者平臺 有開發指南

iOS9配置網絡:

<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>

請看這里? 原文章:http://www.oschina.net/question/262659_149771?fromerr=Y0rzKueR

1. GPS定位:<CoreAudioKit/CoreAudioKit.h>

1. 基本屬性:

1>

CLLocationManager:定位管理器?? 協議:<CLLocationManagerdelegate> 設置代理 實現方法

CLLocation:位置的具體信息(經緯度 等等)

CLHeading:設備移動方向

CLRegion:一個區域(常用子類:CLCircularRegion:圓形 CLBeaconRegion:藍牙

[CLLocationManager locationServicesEnabled] 定位服務是否可用

distanceFilter:自動過濾距離 移動某個距離之后重新調用代理方法 更新位置

desiredAccuracy:定位的精度

self.manager.desiredAccuracy = kCLLocationAccuracyBest; // 最佳精度 self.manager.pausesLocationUpdatesAutomatically = YES; // 不需要的時候可以自動暫停

?

- (void)viewDidLoad {[super viewDidLoad];self.locationManager = [[CLLocationManager alloc] init];self.locationManager.delegate = self;// 允許定位 [self.locationManager requestAlwaysAuthorization];// 自動過濾距離 移動100米之后重新調用代理方法 更新位置self.locationManager.distanceFilter = 100.0; // 米為單位// iOS7的系統下 寫完start就可以開始定位了 [self.locationManager startUpdatingLocation];// 初始化地理編碼器:self.geocoder = [CLGeocoder new]; }

2> CLGeocoder 地理編碼器:

創建:

self.geocoder = [CLGeocoder new];

編碼:提供某個字符串 來定位位置:- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;

[self.geocoder geocodeAddressString:self.inputLocation.text completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {// 取出一個位置信息CLPlacemark *placeMark = placemarks.lastObject;// 輸出信息NSLog(@"%lf %lf", placeMark.location.coordinate.latitude, placeMark.location.coordinate.longitude);}];

反編碼:根據位置顯示該地方的名字等等

[self.geocoder reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {CLPlacemark *place = placemarks.lastObject;self.inputLocation.text = place.name;NSLog(@" %@",place.name);}];

2. 獲取位置信息:

iOS7的系統下 寫完start就可以開始定位了:

[self.locationManager startUpdatingLocation];

?

但是在iOS之后就需要設置是否允許定位:設置完成這個之后才可以定位

requestAlwaysAuthorization:一直允許定位

requestWhenInUseAuthorization:用戶允許

在添加之前需要在info.plist 文件中添加字段:NSLocationAlwaysUsageDescription? (后面的字符串知識提示的時候會顯示 并沒有什么用)

[self.locationManager requestAlwaysAuthorization];

2. 地圖:<MapKit/MapKit.h>

1> iOS原生地圖:

前面帶MK的是系統自帶的地圖:

MKUserLocation:地圖上的大頭針 有title subtitle等屬性

MKMapView:用來顯示地圖 與視圖一樣 初始化需要確定frame 定位的時候需要用到coreLocation框架

showsUserLocation 設置為YES 允許跟蹤定位 (MKMapView的屬性)

可自定義MKAnnotation

// 創建比例系數 顯示在某個點上MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.coordinate, MKCoordinateSpanMake(0.1, 0.1)) ; // 比例系數越小 放大效果越大self.mapView.region = region; // 系統自帶

2> 高德:

多以MA開頭的:

[_mapView setZoomLevel:16.0 animated:YES];? 設置縮放的比例

// 1. 驗證key[MAMapServices sharedServices].apiKey = @“申請的key”;// 2. 初始化mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.bounds))];mapView.delegate = self;// mapView.language = MAMapLanguageEn; // 設置地圖顯示語言mapView.mapType = MAMapTypeStandard; // 地圖類型/*MAMapTypeSatellite:衛星地圖MAMapTypeStandard:標準地圖*/ // mapView.showTraffic = YES; // 顯示實時交通路況 [self.view addSubview:mapView];mapView.showsUserLocation = YES;

mapView的定位模式: userTrackingMode

MAUserTrackingModeNone:不跟隨用戶位置,僅在地圖上顯示。

MAUserTrackingModeFollow:跟隨用戶位置移動,并將定位點設置成地圖中心點

MAUserTrackingModeFollowWithHeading:跟隨用戶的位置和角度移動

系統的地圖和 高德地圖 的區別:http://www.mamicode.com/info-detail-573898.html

?

轉載于:https://www.cnblogs.com/Evelyn-zn/p/4979101.html

總結

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

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