以用户身份放置多个叠加层
我一直在开发一个项目来创建地图(使用谷歌API),用户可以长按来放置自定义叠加层。到目前为止,我已经能够允许用户放置一个覆盖层,但是当您放置第二个覆盖层时,程序崩溃了。我怀疑这是因为该方法尝试重用相同的变量名?这是我正在使用的代码段,任何有关如何实现这一目标的帮助将不胜感激。
@Override
public void onLongPressFinished(MotionEvent e, ManagedOverlay overlay, GeoPoint point, ManagedOverlayItem item) {
if (item != null)
Toast.makeText(getApplicationContext(), "You selected..." + item.getTitle() + "!", Toast.LENGTH_LONG).show();
ManagedOverlay managedOverlay = overlayManager.createOverlay("listenerOverlay", getResources().getDrawable(R.drawable.tankicon));
managedOverlay.createItem(point, "text");
overlays.add(managedOverlay);
overlayManager.populate();
}
}
I've been working on a project to create a map (using googles api) where the user can longpress to place custom overlays. So far I've been able to allow the user to place one overlay, but when you go to place the second the program crashes. I suspect it's because the method attempts to reuse the same variable name? Here's the segment of code I'm using, any help as to how to achieve this would be greatly appreciated.
@Override
public void onLongPressFinished(MotionEvent e, ManagedOverlay overlay, GeoPoint point, ManagedOverlayItem item) {
if (item != null)
Toast.makeText(getApplicationContext(), "You selected..." + item.getTitle() + "!", Toast.LENGTH_LONG).show();
ManagedOverlay managedOverlay = overlayManager.createOverlay("listenerOverlay", getResources().getDrawable(R.drawable.tankicon));
managedOverlay.createItem(point, "text");
overlays.add(managedOverlay);
overlayManager.populate();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请试试这个。这用于在地图视图上显示多个叠加层,可能会解决问题:https://github。 com/donnfelker/android-mapviewballoons
please try this one. This is used for showing multiple overlays on map view, may be it will solve the problem: https://github.com/donnfelker/android-mapviewballoons
为了解决这个问题,我简单地使用了 onDoubleTap 方法而不是 longPress。事实证明,长新闻是有问题的,因为它可能会被误解,有时甚至不起作用。
然而,大部分代码仍然是相同的。
To solve the problem I simply used the onDoubleTap method instead of the longPress. The longPress turned out to be way to problematic as it could be misinterpreted, and sometimes did not work.
The bulk of the code is still the same however.