MKAnnotations are being made successfully, however they sometimes fail to render on MKMapView

Posted by jtkendall on Stack Overflow See other posts from Stack Overflow or by jtkendall
Published on 2010-05-06T14:30:12Z Indexed on 2010/05/14 11:34 UTC
Read the original article Hit count: 278

I'm working on an iPhone app using the 3.1.3 SDK, my app finds the users current location, displays it on a MKMapView and then finds nearby locations and renders them as MKAnnotations. My code is working, however sometimes the nearby annotations do not appear on the map. They are still being made as I see the correct data in the console (from NSLog which runs just after the annotations are made).

When it fails is completely random, it could be the 5th time I've hit "Build and Run" for the day, or the 500th it doesn't appear to have any pattern and doesn't throw any type of error, it just doesn't add the annotations to the MapView.

This is the method called for each nearby location to add the MKAnnotation.

- (void)addPinsWithLocation:(NSDictionary *)spot
{
    CLLocationCoordinate2D location;
    location.longitude = [[spot objectForKey:@"spot_longitude"] doubleValue];
    location.latitude = [[spot objectForKey:@"spot_latitude"] doubleValue];

    PlaceMarks *placemark = [[PlaceMarks alloc] initWithCoordinate:location title:[spot objectForKey:@"spot_name"] subtitle:@""];
    NSLog(@"Adding Pin for Location: '%@' at %f, %f", [spot objectForKey:@"spot_name"], location.latitude, location.longitude);
    [mapView addAnnotation:placemark];
}

Any ideas on how to get MKAnnotations to always show?

© Stack Overflow or respective owner

Related posts about iphone-sdk-3.1.3

Related posts about mkannotation