8

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.

EDIT:

I Followed this guide

mike vorisis
  • 2,786
  • 6
  • 40
  • 74

2 Answers2

11

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

let span = MKCoordinateSpanMake(0.0275, 0.0275)

Edit:

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)
Arpit Dongre
  • 1,683
  • 19
  • 30
  • Thanks for the answer but I tried a 0.1 too but when it draws the destination it zooms again at the default zoom that render has – mike vorisis Nov 25 '16 at 09:48
  • Let me check that myself. – Arpit Dongre Nov 25 '16 at 09:49
  • 1
    Follow that guide if you want http://www.ioscreator.com/tutorials/draw-route-mapkit-tutorial and my map height is 200px (just to test it as mine) – mike vorisis Nov 25 '16 at 09:50
  • I have downloaded their project, I'm guessing you want to zoom out because you can't see the source & destination location in screen properly as they are at the very edge? – Arpit Dongre Nov 25 '16 at 10:43
  • yes exactly, as I use the call out to be open I can't see one of the pins and the call out – mike vorisis Nov 25 '16 at 10:44
  • I see that zoom angle is adjusted as accordingly the route & i can't find an API to adjust zoom level as of yet. I suggest you to add some padding over edges so that both pins are visible properly. I have done the same thing for GoogleMaps. – Arpit Dongre Nov 25 '16 at 10:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129025/discussion-between-arpit-dongre-and-mike-vorisis). – Arpit Dongre Nov 25 '16 at 11:07
  • If it works, do accept the answer. You're welcome :) – Arpit Dongre Nov 25 '16 at 11:32
  • @ArpitDongre Is this applicable for polygon as well? – Saurabh Nov 06 '19 at 05:26
0

You need to setRegion you want to zoom. This link may help you to set region.

Thanks:)

Community
  • 1
  • 1
Karthick Selvaraj
  • 2,387
  • 17
  • 28