tags:

views:

783

answers:

3

Whenever I set the region property of the MKMapKit it doubles the span.

For example:

MKCoordinateRegion currentRegion = map.region; // assume the current center of region is around New-York and the span is 2 by 2
map.region = map.region; // assign the region to itself
MKCoordinateRegion newRegion = map.region; 
// the span of newRegion is different (almost twice than currentRegion)

what's going on here?

+1  A: 

Are you setting the region.center for the MapView too ?

Look at the region property API description of MKMapView:

"Changing only the center coordinate of the region can still cause the span to change implicitly. This is due to the fact that the distances represented by a span change at different latitudes and longitudes and the map view may need to adjust the span to account for the new location. If you want to change the center coordinate without changing the zoom level, use the centerCoordinate instead."

My reading is that this means that your region span settings can be overridden by calculated values based on the center coordinate when you change region.center.

cardinal
No, I don't set region.center. It's just the code I posted. Setting the region of the map to its own region doubles the span.
David Faitelson
A: 

Has anyone figured out more about this? I am seeing the problem on both the simulator and device. It seems like my span is being almost doubled from what I request.

btschumy
A: 

I also get it both on the simulator and the device... iphone SDK 3.0, xcode 3.2.

also simulator for SDK 3.1 does it... don't have a device with 3.1 on it right now to try it.

How could they not find this bug?? What could be more basic than loading and saving your region??

Plenty of other bugs in mapkit too! :-/ it's pretty weak!

BTW if you call regionThatFits you get almost the same region. When you try to set the region, it actually sets something close to (but not always exactly) [mapview regionThatFits:yourregion]

Mike