Search code examples
iosswiftmkmapviewgoogle-maps-sdk-ios

MKMapView visible region padding


Dera colleagues,

I'm struggle to implement visible region with native MKMapView. I need to have an exactly the same feature as Google Map SDK Visible Region.

enter image description here

Basically it means to have a sort of padding in the bottom to following code:

let span = MKCoordinateSpan(latitudeDelta: 0.8, longitudeDelta: 0.8)
let reg = MKCoordinateRegion(center: someMyCoordinate, span: span)
mapView.setRegion(reg, animated: true)

It needs to be like this: once I've add some padding in UIView coordinates, it should shift Map center and adjust zoom to make Coordinate Region fully visible, take into account the padding.

Probably my description Is a bit messy, but if you take a look on this video it becomes absolutely clear.

Thank you in advance!


Solution

  • If you print your visible region you will see that the span will be padded since it needs to fit the view. The center coordinate will still be in the center of the view. I'm not sure what you want to do but I guess it can be archived with

    setVisibleMapRect:edgePadding:animated:
    

    You need to have the region converted to a MKMapRect. See Convert MKCoordinateRegion to MKMapRect on how to do that