使用Swift以编程方式倾斜Mapkit中的地图 [英] Tilt map in Mapkit programmatically using Swift

查看:79
本文介绍了使用Swift以编程方式倾斜Mapkit中的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在启动时倾斜地图. (与用户用两根手指向上或向下滚动时所做的操作相同)

I'd like to tilt the map at startup. (Same as the user does when scrolling up or down with 2 fingers)

使用Swift可以吗?

Is this possible using Swift?

推荐答案

MKMapView类参考: http://goo.gl/djHXPn

MKMapView Class Reference : http://goo.gl/djHXPn

查看camera属性:

相机对象定义了在地图表面上方的一点,从该点可以查看地图.将相机应用于地图具有使地图具有类似3D外观的效果.您可以使用相机旋转地图,使其方向与用户的方向相匹配,或者应用俯仰角倾斜地图的平面.

A camera object defines a point above the map’s surface from which to view the map. Applying a camera to a map has the effect of giving the map a 3D-like appearance. You can use a camera to rotate the map so that it is oriented to match the user’s heading or to apply a pitch angle to tilt the plane of the map.

为该属性分配新的相机会立即更新地图,而不会使更改生效.如果要对摄像机位置的变化进行动画处理,请改用setCamera:animated:方法.

Assigning a new camera to this property updates the map immediately and without animating the change. If you want to animate changes in camera position, use the setCamera:animated: method instead.

您不得将此属性设置为nil.要使地图恢复为平坦外观,请应用俯仰角为0的摄像头,使摄像头直接向下观察到地图表面.

You must not set this property to nil. To restore the map to a flat appearance, apply a camera with a pitch angle of 0, which yields a camera looking straight down onto the map surface.

尝试创建和设置相机(动画或不动画).

Try to create and set a camera (animated or not).

我尝试过自己.这是一个使用方法的示例:

I tried myself. Here is an example of how to use it :

let userCoordinate = CLLocationCoordinate2D(latitude: 58.592725, longitude: 16.185962)
let eyeCoordinate = CLLocationCoordinate2D(latitude: 58.571647, longitude: 16.234660)
let mapCamera = MKMapCamera(lookingAtCenterCoordinate: userCoordinate, fromEyeCoordinate: eyeCoordinate, eyeAltitude: 400.0)

let annotation = MKPointAnnotation()
annotation.setCoordinate(userCoordinate)

mapView.addAnnotation(annotation)

mapView.setCamera(mapCamera, animated: true)

您必须根据自己的位置和想要的倾斜效果找到合适的eyeCoordinate.

You'll have to find your right eyeCoordinate depending on your location and tilt effect you want to have.

这篇关于使用Swift以编程方式倾斜Mapkit中的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆