我按照google hellomapview教程中的说明操作。我得到了一个有效的mapview等。但是没有显示添加到地图中的两个项目。它似乎在某处,因为在指定位置点击会显示添加到项目中的消息。
修改
这是我的源代码。它应该非常接近谷歌教程源代码。
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;
}
}
谷歌教程的源代码是否可以在某处获得?