5

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

Is this possible using Swift?

Floern
  • 33,559
  • 24
  • 104
  • 119
Christian
  • 6,961
  • 10
  • 54
  • 82

2 Answers2

8

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

Look at the camera property :

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.

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.

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).

Edit :

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)

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

Community
  • 1
  • 1
lchamp
  • 6,592
  • 2
  • 19
  • 27
7

Swift 4

This is an easier way: you can set distance, pitch and heading:

let mapCamera = MKMapCamera(lookingAtCenter: userCoordinate, fromDistance: 10000, pitch: 65, heading: 0)
map.setCamera(mapCamera, animated: true)
Channel
  • 2,183
  • 21
  • 16