0

我已经浏览了本教程几次,并试图让一个项目显示在我的地图上,但似乎无法使用它。据我了解,我的代码没有任何错误,但如果有人能够看到为什么我的项目不会覆盖我的地图,那就太棒了。

这是我的地图视图:

public class HelloMapViewActivity extends MapActivity {
    @Override
    protected boolean isRouteDisplayed() 
    {
        return false;
    }

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

        GeoPoint point = new GeoPoint(34420800, -119698200);
        OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");

        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
        HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, HelloMapViewActivity.this);

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);

        MapController mapcontroller = mapView.getController();
        mapcontroller.animateTo(point);
        mapcontroller.setZoom(15);
    }

}

这里也是 itemizedoverlay 类:

public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    Context mContext;

    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
        super(defaultMarker);
        mContext = context;

    }

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

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

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

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



}

我真的只是按照教程进行操作,一切看起来都不错,但它会加载地图,只是在我设定的位置上没有任何项目。也没有错误。任何帮助都会很棒

4

1 回答 1

2

将以下构造函数添加到 HelloItemizedOverlay 类。

public HelloItemizedOverlay(Drawable defaultMarker) { super(boundCenterBottom(defaultMarker)); }

于 2012-02-01T18:41:41.120 回答