is there a way of showing MKMapView from an angle (not directly from the top) on a specific zoom level?
Asked Answered
P

2

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?

Proofread answered 18/10, 2016 at 23:5 Comment(0)
S
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.

Saldana answered 18/10, 2016 at 23:27 Comment(3)
Hm so I found quite similar problem here https://mcmap.net/q/1607645/-tilt-map-in-mapkit-programmatically-using-swift 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 :|Proofread
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 MKMapCameraEmelia
@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 :|Proofread
N
0

try this

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

            self.mapView.isPitchEnabled = true;
            self.mapView.showsBuildings = true;
Nonfeasance answered 2/4, 2017 at 4:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.