0
votes

I'm using MKMapView with many annotations. Everything is OK until i zoom in and zoom out my map. Some annotations' location switch with each others. Anyone know why? Here are my code that i call after viewDidLoad to import annotations from 3 arrays: longitudes, latitudes and photoFileName. photoFileName contains photo file names for all annotations, longitudes and latitudes contain coordinates of them.

for (int i=0; i<[longitudes count]; i++)
CLLocation* location = [[CLLocation alloc] initWithLatitude:[latitudes objectAtIndex:i]
            longitude:[longitudes objectAtIndex:i]];
CSMapAnnotation* annotation = [[CSMapAnnotation alloc] initWithCoordinate:[location coordinate]
            annotationType:CSMapAnnotationTypeImage
            title:@"";
            subtitle:@"";

// Set data for the annotation. This data is used for displaying annotation
[annotation setUserData:[photoFilename objectAtIndex:i]];

[_mapView addAnnotation:annotation];
[annotation release];
[currentLocation release];

}

Everything loaded OK, scrolling and zooming worked. However, when I zoom in mapview (about 5-10 times bigger), and after that, zoom out again to the first size, some annotations locations are changed (See the bottom annotation). I don't post the function viewForAnnotation here because it's not called, i just zoom in/out and it happends. http://cC8.upanh.com/27.800.35078007.mF80/1.png http://cC9.upanh.com/27.800.35078008.AWG0/2.png

1
Are you sure viewForAnnotation: is never called? I think it can be caused by reusing annotationViews.Youssef
Oh, you are right. I solved problem after see again viewForAnnotation function. Here are my old code:toandk
Maybe you should update your question and show how did you fix itYoussef
Oh, you are right. I solved problem after see again viewForAnnotation function. In my old code, when calling [mapView dequeueReusableAnnotationViewWithIdentifier:identifier], i just set identifier to "Image" for all annotations. It makes this function get a random annotation each time. Solved by specifying the true identifier for each annotation. Thanks for your warning!toandk

1 Answers

1
votes

Oh, you are right. I solved problem after see again viewForAnnotation function. In my old code, when calling [mapView dequeueReusableAnnotationViewWithIdentifier:identifier], i just set identifier to "Image" for all annotations. It makes this function get a random annotation each time. Solved by specifying the true identifier for each annotation. Thanks for your warning!