Android应用程序结构问题
我目前正在开发一个使用 MapView 并向其添加叠加层的应用程序。基本上,在任何给定时间,覆盖列表都不应超过两个。
这就是我尝试做的...
我扩展了 ItemizedOverlay 类 (MyFriendOverlay),然后在该扩展类中创建了一个私有 ArrayList 对象,我将把叠加层附加到该对象上。然而;我遇到了一个问题,我不确定如何解决。如果你看一下这段代码:
ImageView mapMarker = new ImageView(getApplicationContext()); mapMarker.setImageResource(R.drawable.markertrp);
myPointsToShow = new myFriendOverlay(mapMarker.getDrawable(), getApplicationContext());
如此处所示,我创建了一个带有基于我的绘图的图标。之后,我从 ItemizedOverlay 获得了扩展课程。在构造函数中,它需要两个参数:可绘制对象和上下文。
据我所知,下面的构造函数是必需的(也许可以修改):
公共 myFriendOverlay(Drawable defaultMarker,Context 上下文) 这里的问题
是我不断创建 myPointsToShow 的新实例,这是一个问题,因为我有一个想要在扩展类中使用的 ArrayList,这样我就可以直接控制覆盖层。通过每次实例化一个新的,我并没有真正添加到列表本身。
简而言之:
我想要的只是我的应用程序有两个点(A 和 B),如果检测到 B 的新位置,则从覆盖列表中删除 B,并将其替换为新地点。 A 也一样。为了简化它,我想将索引 0 附加到 A,将索引 1 附加到 B,这样它就不会跨越两个点。
由于必要的构造函数的问题,我无法为此提出解决方案,也许我想得太仔细了......
请提供任何反馈! :)
感谢您的阅读。
I am currently working on an application that makes use of a MapView and adds overlays to it. Basically at anyone one given time the overlay list should never exceed two.
Heres what I have tried to do...
I have extended the ItemizedOverlay class (MyFriendOverlay) and then created a private ArrayList object inside that extended class that I would attach the overlays to. However; I have come across a problem that I am unsure how to fix. If you look at this segment of code:
ImageView mapMarker = new ImageView(getApplicationContext());
mapMarker.setImageResource(R.drawable.markertrp);
myPointsToShow = new myFriendOverlay(mapMarker.getDrawable(), getApplicationContext());
As can be noted here I am created a ImageView with an icon based on my drawables. After this I have my extended class from ItemizedOverlay. In the constructor it takes two parameter the drawable and the context.
From what I know the constructor below is required (perhaps it can be modified):
public myFriendOverlay(Drawable defaultMarker, Context context)
Problem here is that I keep creating a new instance of myPointsToShow, which is a problem because I have a ArrayList that I want to use in the extended class so I have direct control over the overlays. And by instantiating a new one every time, I don't really add to the list itself.
In short:
All I want is for my application to have two points (A and B) where if a new location is detected for say B, then remove B from the overlay list, and replace it with the new location. And the same for A as well. In order to simplify it, I want to attach index 0 to A and index 1 to B, so that it doesn't span over two points.
I am unable to come up with a solution for this because of the problem of the necessary constructor, perhaps I'm thinking too hard about it...
Please offer any feedback! :)
Thanks for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的经验,我所做的如下:
顺便说一句,您需要使用
R.drawable.something
作为叠加层。您不需要创建ImageView
。我一直在使用这个 android-library 来制作地图:android-mapviewballoons。一探究竟!
From my experience what I do is the following:
Btw you need to use
R.drawable.something
for your overlay. You don't need to create anImageView
.I have been using this android-library for maps: android-mapviewballoons. Check it out!