MKOverlay imposes everything on strange circumstances only on ios5?

I have MKMapViewone that has a very strange problem that is hard to explain. I have MKOverlayone that persists between sessions, saving the overlay points in a file and loading the overlay in viewDidLoad. So here is the problem:

Steps

  • I add MKOverlayinMKMapView
  • On the second or third launch, after adding MKOverlayto the map, everything on the map is superimposed by overlaying the same color as the one I added. Everything on the map, except for the kind of map that you can see when loading a view.

Other weird stuff:

  • This problem only occurs when mapView.showsUserLocationthe truth is established,
  • This problem only occurs on iOS5. Everything works fine on iOS6.
  • If you reduce the size of the color overlay, then the visible part of the map is to fill the map at a new level, at which you zoomed in.

This guy has the same problem, although his solution did not work for me.

Overlay problem using MKPolyline and MKPolylineView

Here is my code:

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

    MKPinAnnotationView *pinView = nil; //switch this to MKAnnotationView and use .image property if pins need to be images

     if(annotation == self.startingPin || annotation == self.endingPin){

        static NSString *defaultPinID = @"com.MagnusDevelopment.pin";

        pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];

        if (pinView == nil)pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinID];

        pinView.canShowCallout = YES;
        pinView.animatesDrop = TRUE;

        if(annotation == self.startingPin){
        //starting pin
            pinView.pinColor = MKPinAnnotationColorGreen;
        }else{
        //ending pin
            pinView.pinColor = MKPinAnnotationColorRed;
        }

    }
    return pinView;
}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolylineView *aView = [[MKPolylineView alloc] initWithPolyline:(MKPolyline *)overlay];
    aView.lineWidth = 7.0;
    aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.6];
    return aView;
}

The code that is called when the view is loaded, I registered the coordinates that are added to the array of the polyline before they are added, and everything will be 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 an image of what happens when the overlay appears, and the user turns to the side on the map: enter image description here Any ideas on what the problem is?

+5
source share
2 answers

dequeueReusableAnnotationViewWithIdentifier, pinView, dequeueReusableAnnotationViewWithIdentifier .

MKPinAnnotationView, :

MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pin == nil) {
    pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
} else {
    pin.annotation = annotation;
}
+1

: mapview , .

.

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

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

PS: .

.

0

All Articles