您的位置:首页 > 移动开发 > IOS开发

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

2017-04-07 12:54 441 查看

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





地图框架 - 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.
}
}

运行效果:







作者:蓝田(Loto)

【作品发布平台】
简书

博客园

Gitbook(如果觉得文章太长,请阅读此平台发布的文章)

【代码托管平台】
Github

【如有疑问,请通过以下方式交流】
评论区回复


发送邮件
shorfng@126.com

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

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

支付宝扫一扫 向我打赏



你也可以微信 向我打赏

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: