MapView mapView = new MapView(this, mapkey);
MapController mc=mapView.getController();
GeoPoint myLocation = null;
Drawable drawable = this.getResources().getDrawable(R.drawable.map_marker);
myItemizedOverlay itemizedoverlay = new myItemizedOverlay(drawable, this);
GeoPoint ppoint = new GeoPoint(platt,plngg); //platt and plngg xml parser value lattitude and Longitude
OverlayItem poverlayitem = new OverlayItem(ppoint,bankname,name of the place);
itemizedoverlay.addOverlay(poverlayitem);
mapOverlays.add(itemizedoverlay);
myLocation = new GeoPoint(platt,plngg);
mc.animateTo(myLocation);
mapView.setBuiltInZoomControls(true);
mapView.setClickable(true);
mc.setZoom(14);
mapView.invalidate();
return mapView;
MyItemizedOverlay 类 --> 用于在地图中绘制图钉
public class myItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
public myItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public myItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
public void addOverlay(OverlayItem overlay){
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
public void removeItem(int i){
mOverlays.remove(i);
populate();
}
@Override
public int size() {
return mOverlays.size();
}
@Override
protected boolean onTap(int i) {
OverlayItem item = mOverlays.get(i);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}