我已经完成了这个教程几次,并尝试让一个项目显示在我的地图上,但似乎无法随意使用它。根据我的理解,我没有任何错误的代码,但如果有人能够看到为什么我的项目不会覆盖我的地图会很棒。
这是我的mapview:
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;
}
}
我真的只是按照教程,一切看起来都是正确但它会加载地图,没有项目将在我设置我的观点。也没有错误。任何帮助都会很棒
答案 0 :(得分:2)
将以下构造函数添加到HelloItemizedOverlay类。
public HelloItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}