1

I'm trying to get my MapKit to zoom to the centre 2 or more points on the map and have them all visible. I managed to successfully get the centre correctly but I can't figure out how to get to fit them all into my region.

This is what I have so far

        let center = middlePointOfListMarkers(listCoords: [location.coordinate,location2.coordinate)
        center.latitude
        let region = MKCoordinateRegionMake(center, MKCoordinateSpan(latitudeDelta: 0.025, longitudeDelta: 0.025))
        self.mapView.setRegion(region, animated: true)

I'm trying to use MKCoordinateRegionMake but there might be an easier way to do this. Please let me know if you guys have any ideas.

Overflowed
  • 134
  • 2
  • 9
  • You need to take the absolute difference between your latitudes and longitudes (Take the max if more than 2 points) and use that for the span – Paulw11 Aug 02 '17 at 00:57
  • See https://stackoverflow.com/questions/1336370/positioning-mkmapview-to-show-multiple-annotations-at-once . As of iOS7 You can use [showAnnotations](https://developer.apple.com/documentation/mapkit/mkmapview/1452309-showannotations) method. – Kosuke Ogawa Aug 02 '17 at 07:54

0 Answers0