Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I expand a MKMapRect by a fixed percentage?

I want to get a result MKMapRect that's 10-20% larger in all directions than the current visibleMapRect. If this were a CGRect I'd use CGRectInset with negative x and y values, providing me with an inverse inset (i.e. a larger rect). Unfortunately, MKMapInset doesn't support negative inset values so it's not quite that easy.

This might be easier if the the values for the map rect were recognizable units but the origin x and y values are on the order of 4.29445e+07, and the width/height is 2500-3000.

I'm about 10 seconds from writing a category to do this manually but I wanted to make sure I wasn't missing something first. Is there an easier way to expand MKMapRect?

like image 852
Nick Avatar asked Jan 09 '13 18:01

Nick


1 Answers

Simple and clean solution for Xcode 10+, Swift 4.2

Just set the edge insets for the maps' margins like this:

self.mapView.layoutMargins = UIEdgeInsets(top: 8, right: 8, bottom: 8, left: 8)
self.mapView.showAnnotations(map.annotations, animated: true)

Please let us know if it works for you.

like image 72
Luiz Dias Avatar answered Oct 21 '22 07:10

Luiz Dias