Reputation: 15669
I am using MapKit
for my project and so far it has been very good. Here is a chunk of code I use for displaying and centering the map.
CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:southWest.latitude longitude:southWest.longitude];
CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:northEast.latitude longitude:northEast.longitude];
CLLocationDistance meters = [locSouthWest distanceFromLocation:locNorthEast];
MKCoordinateRegion region;
region.center.latitude = (southWest.latitude + northEast.latitude) / 2.0;
region.center.longitude = (southWest.longitude + northEast.longitude) / 2.0;
region.span.latitudeDelta = meters / 111319.5;
region.span.longitudeDelta = 0.0;
[self.mapView setRegion:region animated:YES];
The problem is, that it works differently on iPhone 4 and iPhone 5.
Here is iPhone 4 (same results for iOS5 and iOS6):
and here is iPhone 5 (using the same coordinates):
Anybody experiencing the same?
Upvotes: 0
Views: 255
Reputation: 363
These are the lines of code that are causing the difference:
region.center.latitude = (southWest.latitude + northEast.latitude) / 2.0;
region.center.longitude = (southWest.longitude + northEast.longitude) / 2.0;
Which are bound to create a difference since the screen sizes vary.
What you can do here to center the map is to use mapView.centerCoordinate
Upvotes: 1
Reputation: 4870
MapKit has fixed zoom levels. Setting the map's region ensures that the region will be visible in the map, but does not set the exact zoom. This has several benefits, the primary one being you can't create a map that scales latitude and longitude disproportionately (leading to a confusing and/or misleading map). The frames of the maps are different sizes, so your selected region can display at different zoom levels on each device.
As an experiment, try setting the frame of the map view to the same size on both devices. Then, if you absolutely need the maps to display at the same scale you could do some math to compute the appropriate region based on the frame of the map.
Upvotes: 1