MKMapView setVisibleMapRect with completion?
<p>I am having a heck of a time getting around some very annoying behavior in MapKit. Specifically, I want to show a popover annotation view after the map has animated to a certain visible region.</p>
<p>I can use <code>mapView:regionDidChangeAnimated:</code> to get a callback after the map transition (which I will call the &quot;zoom&quot;), but this only fires if the visible region <em>actually changes</em>.</p>
<p>You see the zoom happens in my app when an annotation (or its counterpart in a table view) is selected: I want to zoom the map to essentially focus on the selected annotation.</p>
<p>The problem is that if the map is <em>already</em> in the correct region, I will get no regionDidChange, and therefore no signal to show my popover view.</p>
<p>I am using variants of <code>setVisibleMapRect:</code> to actually perform the zoom. So I <strong>thought</strong> I was being smart by comparing the new and old <code>MKMapRect</code>s to see if they are equal, and if so manually calling my callback.</p>
<p>The problem is it doesn't work! Even if I determine that the two <code>MKMapRect</code>s are <strong>not</strong> equal, by means of <code>MKMapRectEqualToRect</code>, MapKit just sometimes decides it won't fire the regionDidChange event! Perhaps it has to be over a certain delta or something, I don't know.</p>
<p>So my question is: what the heck is the expected best practice for getting a guaranteed completion from <code>setVisibleMapRect:</code>?</p>
<p><strong>Update:</strong> I'm now thinking this might have to do with the <code>edgePadding</code> argument which I am also using:</p>
<pre><code>- (BOOL)vivoSetVisibleMapRect:(MKMapRect)mapRect edgePadding:(UIEdgeInsets)insets animated:(BOOL)animate {
    BOOL equal = MKMapRectEqualToRect(self.visibleMapRect, mapRect);
    NSLog(@&quot;Map rects are: %@&quot;, equal ? @&quot;equal&quot; : @&quot;NOT equal&quot;);
    NSLog(@&quot;%@\n\n%@&quot;, MKStringFromMapRect(self.visibleMapRect), MKStringFromMapRect(newRect));
    [self setVisibleMapRect:mapRect edgePadding:insets animated:animate];
    return !equal;
}
</code></pre>
<p>As you can see, the edge padding is not taken into account in the comparison, yet it is most likely having an effect on the finally computed mapRect.</p>
<p>Does anyone know how I can perform this test to properly take into account <code>edgePadding</code>?</p>
<p><strong>Update 2:</strong> It's now looking like <code>MKMapRectEqualToRect</code> is wrong and therefore completely useless. Check out this log statement:</p>
<blockquote>
<p>2016-03-16 17:06:30.841 Mobile[70089:6240786] Map rects are: NOT equal</p>
<p>{{42403042.3, 91858289.9}, {14878.4, 12832.6}}</p>
<p>{{42403042.3, 91858289.9}, {14878.4, 12832.6}}</p>
</blockquote>
<p>They look pretty darn equal to me!! </p>