为什么我在一个MapView的覆盖没有显示? [英] Why are my overlays on a mapview not shown?

查看:110
本文介绍了为什么我在一个MapView的覆盖没有显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟着从谷歌hellomapview教程中的说明。我得到的工作MapView类等,但被添加到地图中的两个项目都没有显示。似乎他们在那里的某处,因为在指定位置攻丝表明加入到该物品的信息。

I followed the instructions from the google hellomapview tutorial. I get a working mapview etc. But the two items that are added to the map are not shown. It seems they are there somewhere because tapping at the specified location shows the message that was added to the items.

修改

下面是我的源$ C ​​$ C。它应该是非常接近的谷歌教程源$ C ​​$ C。

Here is my source code. It should be very close to the google tutorial source code.

public class MapOverlay extends ItemizedOverlay<OverlayItem> {

private List<OverlayItem> overlays = new ArrayList<OverlayItem>();
private Context context;

public MapOverlay(Drawable defaultMarker, Context context) {
    super(defaultMarker);
    overlays = new ArrayList<OverlayItem>();
    this.context = context;
}

@Override
protected OverlayItem createItem(int i) {
    return overlays.get(i);
}

@Override
public int size() {
     return overlays.size();
}

public void addOverlay(OverlayItem overlay) {
    overlays.add(overlay);
    this.populate();
}

@Override
protected boolean onTap(int index) {
  OverlayItem item = overlays.get(index);
  AlertDialog.Builder dialog = new AlertDialog.Builder(this.context);
  dialog.setTitle(item.getTitle());
  dialog.setMessage(item.getSnippet());
  dialog.show();
  return true;
}

}

public class MapsActivity extends MapActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    MapOverlay overlay = new MapOverlay(this.getResources().getDrawable(
            R.drawable.androidmarker), this);

    overlay.addOverlay(new OverlayItem(new GeoPoint(19240000,-99120000), "Blubb", "See?"));
    mapView.getOverlays().add(overlay);
}

@Override
protected boolean isRouteDisplayed() {
    return false;
}
}

从谷歌的教程源$ C ​​$ C可用的地方?

Is the source code from the google tutorial available somewhere?

推荐答案

的问题是,我忘了设置可绘制的边界。看来,如果的MapView不知道如何使图像也不会显示它。

The problem is that I forgot to set the bounds of the drawable. It seems that if the mapview doesn't know how to align the image it won't show it at all.

我改了行头在我的构造来自:

I changed the first line in my constructor from:

super(defaultMarker);

super(boundCenterBottom(defaultMarker));

和知道它的工作完美。

这篇关于为什么我在一个MapView的覆盖没有显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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