7

In swift I'm using MapKit.

I set up the outlet @IBOutlet weak var mapView: MKMapView!, used the MKMapViewDelegate, and then I'm adding some annotations.

I was wondering if there's a possibility to show my map tilted and disable changing it until user zooms out the map. So basically when he zooms in - from the specific zoom level up to the closest zoom - he would only see this:

enter image description here

instead of this:

enter image description here

and changing this option by scrolling with two fingers should be locked. When user zooms out to some specific zoom level (e.g. country-wise), then it could switch to non-3d map. Is that achievable?

user3766930
  • 5,629
  • 10
  • 51
  • 104

2 Answers2

4

Later edit:

The MKMapView has a property called camera(details here) which is an instance of MKMapCamera. You can use that property to set your desired angle. Be aware that the camera can be pitched only at certain zoom levels. Based on Apple's documentation you can check if the camera can be pitched at any given moment by checking the isPitchEnabled property on the map view object.

Original answer

Try using an instance of MKMapCamera. From the documentation that should allow you to set the desired perspective angle and zoom level by setting it's pitch, headingand altitude properties.

You can read more here.

Mihai Fratu
  • 7,579
  • 2
  • 37
  • 63
  • Hm so I found quite similar problem here http://stackoverflow.com/a/28886295/3766930 but I have some doubts - first, I don't always have the user's location, so I don't know how to initiate the camera without it... Also, is there a way of locking the pitch on a certain level? I don't see any option for it in the docs :| – user3766930 Oct 18 '16 at 23:41
  • 1
    You might not have the user's location, but you have the map location right? That's what you'd use. As for locking values, you should be able to do that that by subclassing MKMapCamera – Ben Kane Oct 27 '16 at 14:06
  • @BenKane culd you give me some example of how could that be made? I went through MKMapCamera methods and I didn't see any possibilities to do so :| – user3766930 Oct 29 '16 at 09:22
0

try this

            camera.pitch = 85.0
            camera.altitude = 223.0
            camera.heading = 31.2

            self.mapView.isPitchEnabled = true;
            self.mapView.showsBuildings = true;
demopix
  • 159
  • 6