2011-09-13 32 views
0

我正在使用带有许多注释的MKMapView。一切都还好,直到我放大和缩小我的地图。一些注释的位置相互切换。有人知道为什么 这里是我调用viewDidLoad从3个数组导入注释的代码:经度,纬度和photoFileName。 photoFileName包含所有注释的照片文件名称,经度和纬度包含它们的坐标。MKMapview注释在放大和缩小后出错

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]; 

}

一切OK加载,滚动和缩放工作。然而,当我放大mapview(大约5-10倍),然后再缩小到第一个尺寸,一些注释位置被改变(见底部注释)。 我不会在这里发布函数viewForAnnotation,因为它没有被调用,我只是放大/缩小它发生的事情。 http://cC8.upanh.com/27.800.35078007.mF80/1.pnghttp://cC9.upanh.com/27.800.35078008.AWG0/2.png

+0

你确定viewForAnnotation:永远不会被调用吗?我认为这可能是由重用annotationView引起的。 – ender

+0

哦,你是对的。我再次查看viewForAnnotation函数后解决了问题。这里是我的旧代码: – toandk

+0

也许你应该更新你的问题,并显示你是如何修复它 – ender

回答

1

哦,你说得对。我再次查看viewForAnnotation函数后解决了问题。在我的旧代码中,当调用[mapView dequeueReusableAnnotationViewWithIdentifier:identifier]时,我只为所有注释设置标识符为“Image”。它使得这个函数每次都得到一个随机的注解。通过指定每个注释的真实标识符来解决。感谢您的警告!