本文並非最終版本,如果想要關註更新或更正的內容請關註文集,聯繫方式詳見文末,如有疏忽和遺漏,歡迎指正。 本文相關目錄: ================== 所屬文集: "【iOS】07 設備工具 " ================== "7.4 定位服務 1.0 簡介" "7.4 定位服務 2. ...
本文並非最終版本,如果想要關註更新或更正的內容請關註文集,聯繫方式詳見文末,如有疏忽和遺漏,歡迎指正。
本文相關目錄:
================== 所屬文集:【iOS】07 設備工具 ==================
7.4 定位服務->1.0 簡介
7.4 定位服務->2.1.1 定位 - 官方框架CoreLocation: 請求用戶授權
7.4 定位服務->2.1.2 定位 - 官方框架CoreLocation: CLLocationManager位置管理器
7.4 定位服務->2.1.3.1 定位 - 官方框架CoreLocation 功能1:地理定位
7.4 定位服務->2.1.3.2 定位 - 官方框架CoreLocation 功能2:地理編碼和反地理編碼
7.4 定位服務->2.1.3.3 定位 - 官方框架CoreLocation 功能3:區域監聽
7.4 定位服務->2.1.4 定位 - 官方框架CoreLocation 案例:指南針效果
7.4 定位服務->2.2 定位 - locationManager框架
7.4 定位服務->3.1 地圖框架MapKit 功能1:地圖展示
7.4 定位服務->3.2 地圖框架MapKit 功能2:路線規劃(導航)
7.4 定位服務->3.3 地圖框架MapKit 功能3:3D視圖
7.4 定位服務->3.4 地圖框架MapKit 功能4:地圖截圖
7.4 定位服務->3.5 地圖框架MapKit 功能5:POI檢索
================== 所屬文集:【iOS】07 設備工具 ==================
地圖框架 - MapKit目錄:
本文目錄:
1.0 應用場景:見上圖
2.0 實現步驟
代碼19:3D視圖 Demo
編譯環境:Xcode 8.0
模擬器版本:iOS 10
Swift版本:3.0
【OC 語言】
#import "ViewController.h"
#import <MapKit/MapKit.h>
@interface ViewController ()
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
// 設置需要看的位置的中心點
CLLocationCoordinate2D center =CLLocationCoordinate2DMake(23.132931, 113.375924);
// 創建3D視圖的對象
// 參數1: 需要看的位置的中心點 參數2: 從哪個地方看 參數3: 站多高看(眼睛的海拔,單位:米)
MKMapCamera *camera = [MKMapCamera cameraLookingAtCenterCoordinate:center
fromEyeCoordinate:CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001)
eyeAltitude:1];
// 設置到地圖上顯示,方法1
[self.mapView setCamera:camera animated:YES];
// 設置到地圖上顯示,方法2
// self.mapView.camera = camera;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
【Swift 語言】
import UIKit
import MapKit
class ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - 3D視圖
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
// 設置需要看的位置的中心點
let center = CLLocationCoordinate2DMake(23.132931, 113.375924)
// 創建3D視圖的對象
// 參數1: 需要看的位置的中心點 參數2: 從哪個地方看 參數3: 站多高看(眼睛的海拔,單位:米)
let camera: MKMapCamera = MKMapCamera(lookingAtCenter: center,
fromEyeCoordinate: CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001),
eyeAltitude: 1)
// 設置到地圖上顯示
mapView.setCamera(camera, animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
運行效果:
本文源碼 Demo 詳見 Github
https://github.com/shorfng/iOS_7.0_Device-Tools
作者:藍田(Loto)
【作品發佈平臺】
① 簡書
② 博客園
③ Gitbook(如果覺得文章太長,請閱讀此平臺發佈的文章)
【代碼托管平臺】
【如有疑問,請通過以下方式交流】
① 評論區回覆
② 發送郵件
至 [email protected]
本文版權歸作者和本網站共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,謝謝合作。
如果覺得我的文章對您有用,請隨意打賞。您的支持將鼓勵我繼續創作!
支付寶掃一掃 向我打賞
你也可以微信 向我打賞