Search code examples
iphoneipadmapkitzoomingregion

MapKit: How Can I Transfer the Exact Same Projection to a New Instance With A Slightly Different Shape?


OK, here's the deal:

I have two views: simple and advanced. On the iPad, they come with a big-ass map view, with a marker that can be moved to indicate a position.

Each view has a different instance of MkMapView. When I switch from one to the other, I want to keep the map at exactly the same position and zoom level, so the user feels as if it is the same map.

However, the shape of the map view is slightly different for each of the views. This is because the advanced search has more stuff above the map.

When I open the map (this is code from an abstract superclass, so both instances get it), I set the region and marker position, like so:

[mapSearchView setRegion:[mapSearchView regionThatFits:[[BMLTAppDelegate getBMLTAppDelegate] searchMapRegion]]];
[myMarker setCoordinate:[[BMLTAppDelegate getBMLTAppDelegate] searchMapMarkerLoc]];

searchMapRegion and searchMapMarkerLoc are static, and reflect the currently displayed map's region and marker location (the center of the map).

Here's the problem:

Because the map is a slightly different shape, there is always a bit of adjusting. This can "bounce" back and forth, so that the map zoom keeps decreasing every time you switch, until you are looking at the whole world.

It doesn't matter whether or not I use regionThatFits. The same thing happens, even with this code:

[mapSearchView setRegion:[[BMLTAppDelegate getBMLTAppDelegate] searchMapRegion]];
[myMarker setCoordinate:[[BMLTAppDelegate getBMLTAppDelegate] searchMapMarkerLoc]];

All I want, is for the exact same zoom and center to be displayed. I don't care is the advanced view cuts a bit off.

How do I get the $#@!! MapKit to stop tweaking the zoom factor?


Solution

  • Just FYI. I solved this by creating a custom model layer class that maintains the scale and center point, and is used by multiple MKMapViews. It works pretty well, but the MapKit does sometimes tweak the scale very slightly to fit one of its "detents."