iOS MKAnnotationView 重复放置而不是重复使用引脚

发布于 2024-12-29 07:59:17 字数 665 浏览 3 评论 0原文

我已经为一堆位置设置了一个带有 MKAnnotationViewMKMapView 。我向服务器设置了异步请求,该服务器在任何给定时间返回屏幕上给定区域内的位置,并在用户拖动地图时发出另一个请求。

然而,图钉会掉落在已经存在的图钉位置,而不是重复使用已经存在的图钉。我认为我的 viewForAnnotation 方法中的行:

MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"Pin"];


if(pinView == nil)
{
    pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"] autorelease];
    [pinView setAnimatesDrop:YES];
}
else
{
    [pinView setAnnotation:annotation];
}

会处理它,但事实并非如此。也许我误解了这些代码行的目的。

任何建议将不胜感激!显然我不想在地图上添加多余的注释,非常感谢任何帮助。

I have set up an MKMapView with MKAnnotationViews for a bunch of locations. I have asynchronous requests set up to a server that returns locations within the given area on the screen at any given time, making another request when the user drags the map.

However, pins drop in places where pins already exist instead of reusing the ones that are already there. I thought the lines in my viewForAnnotation method:

MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"Pin"];


if(pinView == nil)
{
    pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"] autorelease];
    [pinView setAnimatesDrop:YES];
}
else
{
    [pinView setAnnotation:annotation];
}

would take care of it, but it doesn't. Maybe I'm misunderstanding the purpose of those lines of code.

Any suggestions are greatly appreciated! Obviously I don't want superfluous annotations on the map, and any help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心 2025-01-05 07:59:17

您将必须查看地图上已有的注释,并确定来自服务器的图钉是否已放置。如果您有唯一的 ID,则可以使用它,或者比较每个图钉的纬度和经度。

您编写的代码的目的是这样的:创建视图的成本很高,因此当图钉不可见时,可以回收其视图并重用于另一个注释。

You're going to have to look through the annotations already on the map and decide whether the pins from the server are already placed or not. If you have an unique id you can use that, or else compare the latitude and longitude of each pin.

The purpose of the code you wrote is this: Views are expensive to create, so when a pin is not visible, its view can be recycled and reused for another annotation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文