shredder2794 0 Light Poster

Hello all,
I have a MKMapView that is having a very strange problem which is kind of hard to explain. I have an MKOverlay that is saved between sessions by saving the points of the overlay to a file and loading the overlay in viewDidLoad. So here's the problem:

Steps

1) I add an MKOverlay to the MKMapView
2) After closing the simulator and xCode and reopening everything the map gets overlayed by an overlay of the same color as the one I added. Everything on the map with the exception of the view of the map that you can see when the view loaded.

Other weird things:
The problem only occurs after you quit out of the simulator and them reopen it.

This problem only occurs on iOS5. Everything works fine on iOS6.

If you zoom out, the colored overlay re sizes the visible portion of the map to fill the map at the new level at which you zoomed out to. Like to map tiles for unloaded portions of the map are being replaced by an overlay

Here is some of my code:

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;


    MKPinAnnotationView *pinView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:@"com.MagnusDevelopment.pin"];
    if (pinView == nil) {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"com.MagnusDevelopment.pin"];
        pinView.pinColor = MKPinAnnotationColorGreen;
    } else {
        pinView.pinColor = MKPinAnnotationColorRed;
    }

    pinView.annotation = annotation;
    pinView.canShowCallout = YES;
    pinView.animatesDrop = TRUE;
    return pinView;
}



- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolylineView *aView = [[MKPolylineView alloc] initWithPolyline:(MKPolyline *)overlay];

    NSString *lineColor = [self.ud objectForKey:@"lineColor"];
    if([lineColor isEqualToString:@"Red"]){
        aView.strokeColor = [UIColor redColor];
    }else if ([lineColor isEqualToString:@"Blue"]){
        aView.strokeColor = [UIColor blueColor];
    }else if ([lineColor isEqualToString:@"Orange"]){
        aView.strokeColor = [UIColor orangeColor];
    }else if ([lineColor isEqualToString:@"Green"]){
        aView.strokeColor = [UIColor greenColor];
    }else if ([lineColor isEqualToString:@"Black"]){
        aView.strokeColor = [UIColor blackColor];
    }
    aView.lineWidth = [self.ud integerForKey:@"lineSize"];
    return aView;
}

Code called when the view loads, I have logged the coordinates that are being added to the polyline array right before they are added, and everything is fine and dandy!

NSInteger numberOfSteps = pointsArray.count;

    NSLog(@"number of steps: %i",numberOfSteps);

    CLLocationCoordinate2D coordinates[numberOfSteps];
    for (NSInteger index = 0; index < numberOfSteps; index++) {
        CLLocation *location = [pointsArray objectAtIndex:index];
        CLLocationCoordinate2D coordinate = location.coordinate;
        coordinates[index] = coordinate;
    }
    MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps];
    [self.mainMap addOverlay:polyLine];

Here is a picture of what happens when the overlay appears and the user pans to the side on the map:
Imgur image

Any ideas about what the problem is and how to fix it?