jxyiliu
jxyiliu

Reputation: 403

iOS: app crash when setting large region to MKMapView

I must do something wrong, I have code as following:

[_mapView setRegion:region animated:YES]; 

The app crashes in 5.0, 5.1 and 6.1 Simulator when I set a very large region to it.

the region is center at

Then I changed the code to

[_mapView setRegion:[_mapView regionThatFits:region] animated:YES];

The code works for OS 5.0, 5.1 but still crashes on OS 6.1.

Any idea?

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region ' * First throw call stack: (0x2570012 0x206ee7e 0x25f8fb1 0x1f8078d 0xab41f 0xc8a1c7 0xc8a232 0xc8a4da 0xca18e5 0xca19cb 0xca1c76 0xca1d71 0xca289b 0xca2e93 0xca2a88 0xffee63 0xff0b99 0xc8add2 0x91456 0xd7f23 0x2082705 0xbac2c0 0xbac258 0xc6d021 0xc6d57f 0xc6c6e8 0xe701d3 0x2538afe 0x2538a3d 0x25167c2 0x2515f44 0x2515e1b 0x2c227e3 0x2c22668 0xba8ffc 0x4c2fd 0x2725 0x1) libc++abi.dylib: terminate called throwing an exception

Upvotes: 1

Views: 1060

Answers (2)

Scott Bossak
Scott Bossak

Reputation: 2501

You should subtract some degrees of latitude/longitude from the span returned from your API

Upvotes: 0

Adam Wright
Adam Wright

Reputation: 49386

I suspect that the region "span" of 75382.1245843343 by 96613.0758612126 degrees is what's throwing up the problem. That region would cover a world with a circumference of over 8 million kilometres - rather larger than our own. Try using a smaller span that actually defines a region on the Earth?

Upvotes: 4

Related Questions