【问题标题】:MKMapview annotations go wrong after zooming in and zooming outMKMapview 注解在放大缩小后出错
【发布时间】:2011-11-15 22:25:42
【问题描述】:

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

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

}

一切正常,滚动和缩放工作正常。但是,当我放大地图视图(大约 5-10 倍),然后再次缩小到第一个尺寸时,一些注释位置发生了变化(见底部注释)。 我没有在这里发布函数 viewForAnnotation 因为它没有被调用,我只是放大/缩小它就发生了。 http://cC8.upanh.com/27.800.35078007.mF80/1.pnghttp://cC9.upanh.com/27.800.35078008.AWG0/2.png

【问题讨论】:

  • 你确定 viewForAnnotation: 永远不会被调用吗?我认为这可能是由于重用 annotationViews 造成的。
  • 哦,你是对的。再次查看 viewForAnnotation 函数后,我解决了问题。这是我的旧代码:
  • 也许你应该更新你的问题并展示你是如何解决它的
  • 哦,你是对的。再次查看 viewForAnnotation 函数后,我解决了问题。在我的旧代码中,当调用 [mapView dequeueReusableAnnotationViewWithIdentifier:identifier] 时,我只是将所有注释的标识符设置为“图像”。它使这个函数每次都得到一个随机注释。通过为每个注释指定真正的标识符来解决。感谢您的警告!

标签: iphone objective-c xcode mkmapview


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 2011-02-22
    • 2010-12-08
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    相关资源
    最近更新 更多