Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sanity Check an MKCoordinateRegion

Is there any way to quickly test whether an MKCoordinateRegion is good or not? I've swapped latitude for longitude and caused an application crash. I'd like to be able to see whether it's possible to perform a setRegion before I actually do it. Will MKCoordinateRegionMake test the values I give it?

Thanks.

like image 411
nevan king Avatar asked Feb 02 '10 14:02

nevan king


1 Answers

It turns out I had swapped my latitude and longitude somewhere. Here's the code I ended up using:

// check for sane span values
if (currentRegion.span.latitudeDelta <= 0.0f || currentRegion.span.longitudeDelta <= 0.0f) {
    currentRegion.span.latitudeDelta = 1.0f;
    currentRegion.span.longitudeDelta = 1.0f;
}
// check for sane center values
if (currentRegion.center.latitude > 90.0f || currentRegion.center.latitude < -90.0f ||
    currentRegion.center.longitude > 180.0f || currentRegion.center.longitude < -180.0f
    ) {
    // Take me to Tokyo.
    currentRegion.center.latitude = 35.4f;
    currentRegion.center.longitude = 139.4f;
}
like image 57
nevan king Avatar answered Oct 19 '22 18:10

nevan king