0
我已經跑過這個教程幾次,並試圖讓一個項目顯示在我的地圖上,但似乎無法得到它的任何地方。據我的理解,我沒有任何我的代碼錯誤,但如果任何人可能會明白爲什麼我的項目不會覆蓋我的地圖,那將是非常棒的。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;
}
}
我真的只是跟着教程,一切看起來像它的權利,但它會載入地圖只要我確定了我的觀點,就沒有任何東西會出現在它上面。也沒有錯誤。任何幫助將是偉大的
謝謝你,我記得找過該行並想我把它和相信我說過了,但這樣做是 – 2012-02-01 19:04:05
很樂意幫助你:) – 2012-02-01 19:12:37