0

我根据来自 Web 服务的响应 JSON 进行注释。

我可以在地图中加载图钉,但是当我移动中心的位置时,我必须重新加载一组新的注释并删除旧的注释。当我执行该方法时,它只会给引脚充电,如果我移动中心,它也会这样做并充电。

我已经尝试了很多这样的方法......

for (id<MKAnnotation> annotation in _mapView.annotations) {
    [_mapView removeAnnotation:annotation];
}

但它只是这样做:我到达地图的中心,当我移动地图时,它会返回到起点,我无法缩放地图,因为它会重新加载和循环。

4

1 回答 1

1

要删除所有注释,只需在添加新注释之前运行它。

 NSMutableArray *toRemove = [NSMutableArray arrayWithCapacity:15];
for (id annotation in mapView.annotations){
    if (annotation != mapView.userLocation)
        [toRemove addObject:annotation];

    [mapView removeAnnotations:toRemove];
于 2012-06-04T10:22:22.023 回答