To rely on Anna K's explanation, the general recommendation is to check the correctness of CLLocationCoordinate2DIsValid (YOURLOCATION).
If you get lats and longs from a web service or SQLite database, you should check and make sure the location is valid before trying to add annotation to the map. Here is an example of this in action:
for (int i = 0; i < [yourArray count]; i++) { YourOBJ *obj = [yourArray objectAtIndex:i]; yourCLLocation2D.latitude = obj.latitude; yourCLLocation2D.longitude = obj.longitude; AnnotationPin *anno = [[AnnotationPin alloc] initWithCoordinate: yourCLLocation2D]; if (CLLocationCoordinate2DIsValid(yourCLLocation2D)) { anno.lat = obj.latitude;//Maybe you want to store lat anno.lon = obj.longitude;//and lon anno.title = obj.name//define the title anno.subtitle = obj.info//and subtitle for your annotation callout anno.yourLocation = yourCLLocation2D;//Some of these aren't necessary anno.tag = i;//but can really help to define and track pins [map addAnnotation:anno]; } [anno release]; }
For all those who have problems, when you add a bunch of contacts to the card successfully, and with the same code try to add another set of contacts, but the application will fail, try this as soon as possible. For those who have a similar situation in this example, but have not encountered any problems, do it anyway! Your users may add the wrong lat / lon combination and application crash if you provide them with this functionality.
Remember that (0,0) is the actual coordinate, so don't worry about this logic by deleting them if that bothers you. This is for those (-200.75) coordinate types that do not physically exist on planet Earth.
whyoz source share