Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indifferent behaviour of zoom level in IOS 6 mapview

I have been using the following code to zoom the mapview, so that all the annotations will be displayed in the view at the same time at optimum zoom level. But in IOS 6, there seems to be some problem with the zoom level. Testing a few cases, I found that 1. If the contacts are in US, when the map is loaded it is zooming else where. 2. The zoom level seems to be correct in the UK area(as far as I have tested). 3. When I include contacts from both UK and US, the UK contacts gets rightly zoomed, but the US contacts are out of the view. But a slight swipe will ensure that all contacts fit into the view and are zoomed properly.

-(void)zoomToFitMapAnnotations:(MKMapView*)mapViews insideArray:(NSArray*)anAnnotationArray
{ 
if([mapViews.annotations count] == 0) return;

CLLocationCoordinate2D topLeftCoord;
topLeftCoord.latitude = -90;
topLeftCoord.longitude = 180;

CLLocationCoordinate2D bottomRightCoord;
bottomRightCoord.latitude = 90;
bottomRightCoord.longitude = -180;

for(MKPointAnnotation* annotation in anAnnotationArray)
{
    topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
    topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);

    bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
    bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
}

MKCoordinateRegion region;
region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; // Add a little extra space on the sides
region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // Add a little extra space on the sides

region = [mapViews regionThatFits:region];
[mapView setRegion:region animated:YES];
}

After loading the mapview with annotations, in random cases I get the following log

<GEOTileSource: 0x108f6470>: Error downloading tiles Server Error: Error Domain=GEOErrorDomain Code=-204 "The operation couldn’t be completed. (GEOErrorDomain error -204.)" UserInfo=0x18a5b9c0 {UnderlyingErrors=(
"Error Domain=GEOErrorDomain Code=-204 \"The operation couldn\U2019t be completed. (GEOErrorDomain error -204.)\""
)}

What could be the reason for this and how can I correct it? Couldn't find anything helpful after googling.

I am not able to identify any particular pattern for this zooming inconsistency. The above code is working fine in previous IOS versions.

like image 800
Xavi Valero Avatar asked Nov 03 '22 14:11

Xavi Valero


1 Answers

I almost offered a bounty on your question but then I noticed, that with the new maps in iOS6 you just cannot zoom out to see the whole world (try it yourself in the maps app). There is a maximum zoom level which you can figure out by commenting out your for loop and logging this:

NSLog(@"region.span.latitudeDelta = %f", region.span.latitudeDelta);
NSLog(@"longitudeDelta = %f", region.span.longitudeDelta);

[map setRegion:region animated:NO];

NSLog(@"region.span.latitudeDelta = %f", map.region.span.latitudeDelta);
NSLog(@"longitudeDelta = %f", map.region.span.longitudeDelta);

The output looks like this:

region.span.latitudeDelta = 179.283409
longitudeDelta = 360.000000
region.span.latitudeDelta = 76.269114
longitudeDelta = 98.437499
like image 50
borisdiakur Avatar answered Nov 08 '22 09:11

borisdiakur