如何制作可变的 ItemizedOverlay

发布于 2024-08-18 05:38:35 字数 522 浏览 6 评论 0原文

我想制作一个带有可更改引脚的谷歌地图叠加层。一种简单的可视化方法是考虑近乎实时的覆盖,其中引脚不断改变位置。

但是,我似乎想不出一种安全的方法来使用 ItemizedOverlay。问题似乎是对 populate 的调用 - 如果某些地图线程调用 size(),然后我的数据发生更改,则地图调用访问 getItem() 时的结果可能是 IndexOutOfBoundsException。

有谁能想到比重载 populate 并将 super.populate 包装在同步块中更好的解决方案吗?

也许我可以使用普通的叠加层获得更好的运气?分项似乎是为您管理数据而存在的,也许我使用它犯了一个根本性错误?

感谢您的帮助,我的大脑受伤了!

哈米

I would like to make a Google map overlay with changable pins. An easy way to visualize this would be to think of a near real time overlay, where the pins are constantly changing location.

However, I can't seem to think of a safe way to do this with the ItemizedOverlay. The problem seems to be the call to populate - If size() is called by some maps thread, and then my data changes, then the result when the maps call accesses getItem() can be an IndexOutOfBoundsException.

Can anyone think of a better solution than overloading populate and wrapping super.populate in a synchronized block?

Perhaps I could get better luck using a normal Overlay? The Itemized one seems to exist to manage the data for you, perhaps I am making a fundamental mistake by using it?

Thanks for any help, my brain is hurting!

Hamy

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

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

发布评论

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

评论(2

凑诗 2024-08-25 05:38:35

如中提到的
本文

您需要调用从列表中添加或删除项目后执行以下操作。

setLastFocusedIndex(-1);

填充();

例子:

@Override
protected OverlayItem createItem(int i) {
    return overlays.get(i);
}
protected void removeOverlay(OverlayItem o){
    overlays.remove(o);
    setLastFocusedIndex(-1);
    populate();
}
@Override
public int size() {
    return overlays.size();
}
public void addOverlay(OverlayItem o){
    overlays.add(o);
    setLastFocusedIndex(-1);
    populate();
}

as mentioned in
this article

You need to call the following after adding or removing an item from the list.

setLastFocusedIndex(-1);

populate();

Example:

@Override
protected OverlayItem createItem(int i) {
    return overlays.get(i);
}
protected void removeOverlay(OverlayItem o){
    overlays.remove(o);
    setLastFocusedIndex(-1);
    populate();
}
@Override
public int size() {
    return overlays.size();
}
public void addOverlay(OverlayItem o){
    overlays.add(o);
    setLastFocusedIndex(-1);
    populate();
}
灵芸 2024-08-25 05:38:35

我遇到了类似的问题,并通过相互排除(是的...使它们同步)方法大小更新(添加/更改)引脚的方法解决了。 。
事实上,第一个是由 GUI 线程调用的,而第二个是在异步工作线程中调用的,因此它们可能是异步调用的

I had a similar problem and solved by mutually excluded (yes... making them synchronized) the method size and the method that update (add/change) the pins...
In fact, the first was called bye the GUI thread while the second is in a async worker so it is possible that they are called asynchronously

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