mike vorisis mike vorisis - 1 year ago 207
iOS Question

Change the region (zoom) for mapView Swift

I have a map and I draw a destination between two pins and I have also always open one call out.

My problem is that I want to zoom out a little bit more but I tried to do it with this code and it didn't work.

let span = MKCoordinateSpanMake(0.0275, 0.0275)
let coodinate = self.meLocation!
let region = MKCoordinateRegion(center: coodinate, span: span)
self.mapView.setRegion(region, animated: true)

I assume that making the line for the destination do the problem:

func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
let renderer = MKPolylineRenderer(overlay: overlay)
renderer.strokeColor = UIColor(red: 2.0/255.0, green: 202.0/255.0, blue: 246.0/255.0, alpha: 1.0)
renderer.lineWidth = 2.8

return renderer


So my question is how I can zoom out a little bit more by default.


I Followed this guide

Answer Source

The level of zoom depends on the span. Try changing these values:

let span = MKCoordinateSpanMake(0.0275, 0.0275)


As per discussion, padding is better suited for your Map.

Try padding the edges like this:

self.mapView.setVisibleMapRect(self.mapView.visibleMapRect, edgePadding: UIEdgeInsetsMake(40.0, 20.0, 20, 20.0), animated: true)

Change the values for better fit.

Note: Call it after:

self.mapView.setRegion(MKCoordinateRegionForMapRect(rect), animated: true)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download