我想在谷歌地图上显示多个引脚,但它只显示一个引脚。我正在使用此代码
http://eagle.phys.utk.edu/guidry/android/mapOverlayDemo.html
但它只在第一个位置显示一个引脚。
如何显示多个引脚?
这是我到目前为止所做的:
public class EventMap extends MapActivity {
MyLocationOverlay me = null;
Vector<OverlayItem> overlay;
List<Overlay> mOverlay;
private Drawable drawable1;
MapOverlay itemizedoverlay;
private MapView mapView;
private OverlayItem [] accessItem = {
new OverlayItem( new GeoPoint(35953700,-83926158), "Access Title 1", "Access snippet 1"),
new OverlayItem( new GeoPoint(35954000,-83928200), "Access Title 2", "Access snippet 2"),
new OverlayItem( new GeoPoint(35955000,-83927558), "Access Title 3", "Access snippet 3"),
new OverlayItem( new GeoPoint(35954000,-83927158), "Access Title 4", "Access snippet 4")
};
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.event_map);
MapController mMapController;
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
mapView.setTraffic(false);
mMapController = mapView.getController();
GeoPoint gp = new GeoPoint(35954200,-83929200);
mMapController.animateTo(gp);
mMapController.setZoom(5);
setOverlay();
//mapView.invalidate();
}
public void setOverlay()
{
mOverlay = mapView.getOverlays();
drawable1 = getParent().getResources().getDrawable(R.drawable.pin);
itemizedoverlay = new MapOverlay(drawable1);
for(int i=0; i<accessItem.length;i++)
{
itemizedoverlay.addOverlay(accessItem[i]);
}
mOverlay.add(itemizedoverlay);
}
public class MapOverlay extends ItemizedOverlay<OverlayItem> {
Context ctx;
private ArrayList<OverlayItem> items;
public MapOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
items = new ArrayList<OverlayItem>();
populate();
}
public MapOverlay(Drawable defaultMarker, Context ctx) {
super(boundCenterBottom(defaultMarker));
this.ctx = ctx;
items = new ArrayList<OverlayItem>();
populate();
}
@Override
protected OverlayItem createItem(int i) {
return items.get(i);
}
@Override
public int size() {
return items.size();
}
public void removeItem(int i){
items.remove(i);
populate();
}
@Override
protected boolean onTap(int index) {
Toast.makeText(getParent(),items.get(index).getSnippet(),Toast.LENGTH_SHORT).show();
return true;
}
public void addOverlay(OverlayItem overlay) {
items.add(overlay);
populate();
}
}
}
提前致谢