Android中的多个重叠项目 [英] Multiple overlay items in android

查看:82
本文介绍了Android中的多个重叠项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎在使用ItemizedOverlay和OveralyItems时遇到问题。

I seem to be having a problem with using ItemizedOverlay and OveralyItems in it.

我可以得到第一个overlayItem出现在地图上,但没有任何项目

I can get the first overlayItem to appear on the map but not any items after that.

代码示例为:
http://www.anddev.org/multiple_overlay_items-t12171.html

快速概述:

public class Markers extends ItemizedOverlay {

 private Context ctx;

 private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

 public Markers(Drawable defaultMarker, Context cont) {

      super(boundCenterBottom(defaultMarker));
      this.ctx = cont;
      // TODO Auto-generated constructor stub
 }

 @Override
 protected OverlayItem createItem(int i) {
      // TODO Auto-generated method stub
      return mOverlays.get(i);
 }

 @Override
 public boolean onTap(GeoPoint p, MapView mapView) {
      // TODO Auto-generated method stub
      return super.onTap(p, mapView);
 }


 @Override
 protected boolean onTap(int index) {
      // TODO Auto-generated method stub
      Toast.makeText(this.ctx, mOverlays.get(index).getTitle().toString()+", Latitude: "+mOverlays.get(index).getPoint().getLatitudeE6(), Toast.LENGTH_SHORT).show();
      return super.onTap(index);         
 }

 @Override
 public int size() {
      // TODO Auto-generated method stub
      return mOverlays.size();
 }

 public void addOverlay(OverlayItem item) {
      mOverlays.add(item);
      setLastFocusedIndex(-1);
      populate();

 }

 public void clear() {
      mOverlays.clear();
      setLastFocusedIndex(-1);
      populate();
 }
}

如何使用示例:

Markers usersMarker = new Markers(user,overview.this); 
GeoPoint p = new GeoPoint((int) (lat * 1E6),(int) (lon * 1E6));
OverlayItem item = new OverlayItem(p,userData[0],userData[3]);
item.setMarker(this.user);
usersMarker.addOverlay(item); 

第一个标记显示在地图上,但如果我再添加不显示? populate()方法有问题吗?我尝试在添加所有标记后手动调用它,但仍然没有帮助。请问,如果你有任何想法可能是错误的,请说这样。

the first marker shows up on the map but if I add any more they don't show up? Is there a problem with the populate() method? I tried calling it manually after adding all markers but it still didn't help. Please, if you have any idea what could be wrong, say so.

推荐答案

我终于找到了一个答案。我很遗憾承认它,但是问题不在于没有画画的东西,而是在我看不到他们在屏幕上....这2个项目的位置应该是几乎相同...但其中之一是用一个错误计算,并在世界的一半移动。

I have finally found an answer. I'm quite ashamed to admit it but the problem was not in the items not drawing but in me not seeing them on screen....The locations for the 2 items were supposed to be nearly identical...but one of them was calculated with a bug and was moved halfway round the world.

所以我从来没有打扰过去看看或缩小...当我发现我的另一个标记坐在Barren海里的某个地方:)感谢所有试图帮助的人我...哦,上面的代码工作:)

So I never bothered to look or zoom out...when I did i found my other marker sitting somewehre in the Barren's sea :) Thanks to all who tried to help me...oh and the above code works :)

这篇关于Android中的多个重叠项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆