Question

I'm trying to center my mapView on the user's location, but an exception is thrown that's caught by the AppDelegate before the mapView or view controller are even loaded.

mapView is an MQMapView userLocation is assigned earlier from mapView.userLocation.location.coordinate

MQCoordinateSpan userSpan = MQCoordinateSpanMake(1000, 1000);

MQCoordinateRegion userRegion = MQCoordinateRegionMake(userLocation, userSpan);

[mapView setRegion:userRegion animated:true];

As far as I can make out from the MapQuest developer guide I'm calling setRegion correctly. Any idea what might be causing the exception?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top