1

I have a function that 'centers' the view between all annotations, that was taken from a kind coder here on SO: https://stackoverflow.com/a/7200744/1497534

Everything works fine, until you have annotations very far away from each other. One can place an annotation in San Francisco and Central China, and it works fine. The function that centers the view will place you in Europe, because the zoom level is maxed. That behavior is what I want.

However, if you place an icon in San Francisco, and in Japan, the app crashes with this exception:

Invalid Region <center:+39.84104733, +8.77916614 span:+178.18954061, +450.00000000>

Also note, that this only happens in portrait mode. Landscape can handle everything.

Is this because it is trying to zoom more than the mapkit can zoom?

Does it have to do with how the annotations are initially loaded, and then dequeued with dequeueWithReuseIdentifier? I have this in viewWillAppear:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(createAnnotations:) name:@"CreateAnnotations" object:nil];

I've hit a brick wall and would love some feedback.

Community
  • 1
  • 1
Katamaritaco
  • 315
  • 4
  • 12
  • Add an exception breakpoint and then it'll show you exactly where the exception is coming from. http://developer.apple.com/library/ios/#recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html – iwasrobbed Jun 21 '13 at 21:14
  • The longitude delta is 450. I believe the maximum allowed is 360 or 359. What you could try is set visibleMapRect to MKMapRectWorld if the longitude delta is greater than 359 or so. Latitude delta would have the same issue (should be less than 180). –  Jun 21 '13 at 21:41

1 Answers1

0

The problem is probably because the region that you make spans the 180th meridian. I'm not sure about a solution, but you could try subtracting 360 from any longitude over 360. (Again, I've no idea if this will work, just an idea).

I would have thought that central China and San Francisco would have had the same problem too though. It could be the latitude value too. I think the map view latitude only goes to about 80 degrees North and -80 South (a 160 degree latitude delta). Try substituting different values into the region before setting it to see what's causing the problem.

nevan king
  • 112,709
  • 45
  • 203
  • 241