【iOS】7.4 定位服务->3.3 地图框架MapKit 功能3:3D视图

本文并非最终版本,如果想要关注更新或更正的内容请关注文集,联系方式详见文末,如有疏忽和遗漏,欢迎指正。


本文相关目录:
================== 所属文集:【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(如果觉得文章太长,请阅读此平台发布的文章)

【代码托管平台】

Github

【如有疑问,请通过以下方式交流】

评论区回复
发送邮件shorfng@126.com


本文版权归作者和本网站共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,谢谢合作。


如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
  • 支付宝扫一扫 向我打赏

  • 你也可以微信 向我打赏

原文地址:https://www.cnblogs.com/shorfng/p/6677635.html