0

I would like to know how to centre a route on a MapView. Or how to calculate the center to ensure that both points are also visible on the mapview?

At present I use the setRegion method with some custom calculations to work out the zoom.

[_mapView setRegion:viewRegion animated:YES];

I see that I can also use setVisibleMapRect: edgePadding: animated: but I am not sure how to get a MKMapRect for use.


I find the address of a business with geocodeAddressString then have a CLPlaceMark result.
I have an MKPointAnnotation which is the pin for the destination (business).
I then create a MKDirectionRequest to an MKPlaceMark created from the CLPlaceMark. I then display the route.

How do I zoom in to a specific amount based on this workflow, so that I could get a result like these below. Specifically where the route is centered in the mapView and both user location and the annotation are shown on screen without being miles/very far out?

enter image description hereenter image description hereenter image description here

StuartM
  • 6,743
  • 18
  • 84
  • 160
  • 1
    The directions request returns polyline(s). You can use the boundingMapRect of the polyline(s) as the parameter to setVisibleMapRect. See http://stackoverflow.com/questions/19799887/setregion-to-encapsulate-route. –  Jul 19 '14 at 15:36
  • Thanks are you marking as dup or submitting as an answer, this worked great for me – StuartM Jul 23 '14 at 15:13

0 Answers0