Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapView in iOS6 won't show certain zoom levels at latitude > 75 north

This code sets a default zoom level centered around a specified location in viewDidLoad. The code works fine in previous versions of iOS:

CLLocationDistance visibleDistance = 100000; // 100 kilometers
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, visibleDistance, visibleDistance);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:region];
.
.
.
[mapView setRegion:adjustedRegion animated:NO];

However, in iOS6 for locations with latitude above ~ 75 (>75.1) the app crashes with the following message:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Invalid Region <center:nan, nan span:nan, nan>'

I found that for the given zoom level mapView can't set a proper MKCoordinateRegion internally. [mapView regionThatFits:region] returns all values as nan. If I use the region variable directly, it just shows the default map (the whole world).

After some testing I found that by adjusting the visibleDistance I can get the code to work properly. The magic distance seems to be slightly above 20 kilometers (somewhere between 22 and 23 km for a series of latitudes and latitudeDelta values). This happens only on northern latitudes (-80 works just fine).

The maps work at any location after the initial positioning. It looks like Apple changed the way visible map regions are initialized. I'm using a higher zoom level for the affected region as a workaround. Is there any other way to make it work properly?

like image 986
Neur0mans3r Avatar asked Sep 24 '12 16:09

Neur0mans3r


3 Answers

CLLocationDistance visibleDistance = 100000; // 100 kilometers
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, visibleDistance, visibleDistance);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:region];
.
.
.
[mapView setRegion:adjustedRegion animated:NO];

It will work..

like image 90
Prakruti Joshi Avatar answered Nov 03 '22 18:11

Prakruti Joshi


CLLocationCoordinate2D southwest, northeast;
southwest.latitude = 34.172684;
southwest.longitude = -118.604794;
northeast.latitude = 34.236144;
northeast.longitude = -118.500938;
BSForwardGeocoderCoordinateBounds *bounds = [BSForwardGeocoderCoordinateBounds boundsWithSouthWest:southwest northEast:northeast];

try this....

like image 5
Maulik Vekariya Avatar answered Nov 03 '22 18:11

Maulik Vekariya


I was having crashes with my iPhone4S and console revealed nan values for region. After trying about 7 different solutions from SO and various suggestions from Apple DTS, I solved it by eliminating the regionThatFits call. I simply used:

CLLocationDistance visibleDistance = 100000; // 100 kilometers
MKCoordinateRegion adjustedRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, visibleDistance, visibleDistance);

[_mapView setRegion:adjustedRegion animated:YES];

Apparently there is a problem with that regionThatFits method.

like image 4
marciokoko Avatar answered Nov 03 '22 17:11

marciokoko