itemizedoverlay不会在地图上显示任何项目
问题描述:
我已经跑过这个教程几次,并试图让一个项目显示在我的地图上,但似乎无法得到它的任何地方。据我的理解,我没有任何我的代码错误,但如果任何人可能会明白为什么我的项目不会覆盖我的地图,那将是非常棒的。itemizedoverlay不会在地图上显示任何项目
这是我的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;
}
}
我真的只是跟着教程,一切看起来像它的权利,但它会载入地图只要我确定了我的观点,就没有任何东西会出现在它上面。也没有错误。任何帮助将是伟大的
答
将以下构造函数添加到HelloItemizedOverlay类。
public HelloItemizedOverlay(Drawable defaultMarker) { super(boundCenterBottom(defaultMarker)); }
谢谢你,我记得找过该行并想我把它和相信我说过了,但这样做是 – 2012-02-01 19:04:05
很乐意帮助你:) – 2012-02-01 19:12:37