I developed a game some time ago. The game consists on a map of spain, and you have to guess where a city is on that map (I have EEUU and china versions too) I developed all of them with iOS 5 base, and using iOS 5 sdk.
Then, 3 weeks ago I updated the spanish game and I had to use the iOS 6 sdk, all seems fine on the simulator and on my ipad 2 (iOS 5.0.1) and iPod touch (iOS 5.1) and released the update.
But when people started downloading or updating the new version, some of them contacted me because the map didn't fit to the screen.
this is the screenshot of how do I see the game on my devices and simulator. (iPad 5.0.1 and simulator with 5.0, 6.0 and 6.1, in both retina and normal mode)
this is a screenshot of how does it shown on other people devices. (iPad 3 with iOS 6.0 and iPad 2 with iOS 6.0.1 )
This is my code for iPad (as far as I know, on iPhone is working as expected)
CLLocationCoordinate2D centerLocation;
MKCoordinateRegion region;
centerLocation.latitude = 39.016740;
centerLocation.longitude = -5.93504;
region = MKCoordinateRegionMakeWithDistance(centerLocation, 0, 800000);
[map setRegion:region];
at first I thought it was a retina issue, because the first person who contacted my was using an iPad 3, I fixed the map for iPad retina on monday, but yesterday I got the same message from another user with an iPad 2.
So, am I doing something wrong? is setRegion inconsistent between iOS versions? how can I test my code if it works fine on simulators?
Can somebody try my code on real devices and tell me if they get the map like the first one or the second one?
EDIT1: Final thoughts after accepting the answer: This wasn't an problem between iOS versions, it appears to be a timing problem, the region is different if you set it before the view appears or after. It happens in both, iOS 5 and iOS 6.
The only difference between iOS 5 and iOS 6 happens on real devices, if you set the region before the map appears, it stays as it is, but on iOS 6 on the simulator it will remain as it is, but on the real device, it will be displayed as the region setted when the view appears.
So, the solution is setting the region on viewDidAppear
and it will be displayed the same way on iOS 5 and iOS 6, on simulators and real devices.
EDIT 2:
it seems the 0 on the region had something to do with the problem too, if I use region = MKCoordinateRegionMakeWithDistance(centerLocation, 800000, 800000);
the region is the same before and after the view load, at least on the simulator.
If I use region = MKCoordinateRegionMakeWithDistance(centerLocation, 0, 800000);
the region is different if I use it before the view loads, and appears "zoomed" when I use it later.
I'll wait until I receive my iPad retina with iOS6 to continue testing this issue.
There a few important differences in the way regions work in iOS 5 and 6. On iOS 5, the region that you ask to be set will rarely be the actual region that gets set. This is to do with MapKit on iOS 5 always setting a region that allows the tile images to be displayed at a 1:1 ratio. On iOS 6, there are no tile images and everything is drawn from vector data, so the region that you get is very close to the region that you ask for.
That being said, I think the problem with your code might be the timing. I could reproduce your problem when I set the map's region in viewDidLoad:
, even when I used a proper span (instead of using 0
for the latitude delta). When I moved the code to -viewDidAppear:
, the region set properly on an iPad with iOS 6, as well as the Simulator with iOS 6. Here's the code I used:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CLLocationCoordinate2D centerLocation =
CLLocationCoordinate2DMake(39.016740, -5.93504);
MKCoordinateSpan span = MKCoordinateSpanMake(12.7, 12.7);
MKCoordinateRegion region = MKCoordinateRegionMake(centerLocation, span);
[self.mapView setRegion:region animated:NO];
}
I used 12.7
as the latitudeDelta
and longitudeDelta
. It's good to make the region a square to that the region will have the important places in landscape and portrait mode. You'll need to import the Core Location framework if you want to use the CLLocationCoordinate2DMake()
function.
So I think that the problem is that MapKit is setting the region after you try to set it (on iOS 6). You can check the region being set in -mapView:regionDidChangeAnimated:
with the following code:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
NSLog(@"%f %f %f %f",
self.mapView.region.span.latitudeDelta,
self.mapView.region.span.longitudeDelta,
self.mapView.region.center.latitude,
self.mapView.region.center.longitude);
}
So, if your code is setting the region in -viewDidLoad:
, try moving it to -viewDidAppear:
.
Your coordinate region is very strange — I wouldn't be surprised if MapKit was ignoring it completely.
The centre of (39.016740, -5.93504) looks fine but you're stating that, ideally, your view would show 0 metres of latitude (ie, would have zero height) and 800 km of longitude.
Have you tried supplying a sensible latitude value?
on ios 5 you have mapkit using google maps and ios 6 you have mapkit using built-in maps , there are likely to be differences -- especially visual wise
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With