MKMapView visibleMapRect twice - different results

263 Views Asked by At

I have a view that calls visibleMapRect twice on a MKMapView with the same value both times. The first time it loads as expected (the map changes the visibleMapRect, though that's expected). The second time I re-use the visibleMapRect I used the first time, and end up with a different origin. Is there something special I need to do? I would expect the same results with the same visibleMapRect.

1

There are 1 best solutions below

2
Timothy Moose On

Setting the visibleMapRect is effectively the same thing as setting the region and the documentation for region says:

When setting this property, the map may adjust the new region value so that it fits the visible area of the map precisely. This is normal and is done to ensure that the value in this property always reflects the visible portion of the map. However, it does mean that if you get the value of this property right after setting it, the returned value may not match the value you set. (You can use the regionThatFits: method to determine the region that will actually be set by the map.)

So, if you set visibleMapRect with a given origin and then check the map views value for visibleMapRect, you can get a different origin.

This has nothing to do with setting the map rect twice, but from your brief description, this is my best guess. If this is not helpful, please elaborate a bit more.