views:

548

answers:

2

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.

+1  A: 
TechZen
Thanks for the answer and the edit. The maximum value for longitude is 180°, but for latitude it's only 90°. I had swapped them somewhere else in the code, but your answer gave me a hint about the code to write.http://en.wikipedia.org/wiki/Latitude
nevan
Dang, I knew that! Somewhere my old scout master is rolling over in his grave. Weird how you get stuck on an idea even though you know better. Of course, this does explain why I hit the iceberg.
TechZen
A: 

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 > 360.0f || currentRegion.center.longitude < -180.0f
    ) {
    // Take me to Tokyo.
    currentRegion.center.latitude = 35.4f;
    currentRegion.center.longitude = 139.4f;
}
nevan