gpt4 book ai didi

iphone - 在 xCode 中对 Web 服务收费时出现重复的 MKAnnotations

转载 作者:行者123 更新时间:2023-11-29 04:37:55 24 4
gpt4 key购买 nike

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

我可以加载 map 中的图钉,但是当我移动中心的位置时,我必须重新加载一堆新的注释并删除旧的注释。当我执行该方法时,它只会为引脚充电,如果我移动中心,它也会执行相同的操作并充电。

我尝试过很多像这样的方法......

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

但它只会这样做:我到达 map 的中心,当我移动 map 时,它会返回到开头,并且我无法缩放 map ,因为它会重新加载并循环。

最佳答案

要删除所有注释,只需在添加新注释之前运行此命令即可。

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

[mapView removeAnnotations:toRemove];

关于iphone - 在 xCode 中对 Web 服务收费时出现重复的 MKAnnotations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10825202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com