在Android的多次套印项目 [英] Multiple overlay items in android

查看:126
本文介绍了在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.

code样品是: http://www.anddev.org/multiple_overlay_items-t12171.html

Code sample is on: 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();
 }
}

样品如何使用它:

Samples of how it's used:

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); 

第一个标记显示了在地图上,但如果我添加任何他们不露面?是否有与填充()方法的问题?我尝试添加所有标记后手动调用它,但它仍然没有帮助。请,如果您有任何想法可能是错误的,这样说。

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.

所以我从来没有费心去寻找或缩小......当我做了,我发现我的其他标记坐在荒芜的海:)感谢somewehre所有谁试图帮助我...哦,和上面的code工作原理:)

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天全站免登陆