mapOverlay を作成します。
public class MapOverlay extends Overlay {
MapView mapView;
GeoPoint p;
private Context c;
public MapOverlay(Context c, MapView m, GeoPoint p){
this.c=c;
mapView=m;
this.p=p;
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(c.getResources(), R.drawable.icon_notif);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
}
}
これは、マップを開始するメソッドです。
private void initMapa() {
try{
//If you want zoom controls
mapa.setBuiltInZoomControls(true);
GeoPoint loc;
Double lat;
Double long;
MapController controlMapa = mapa.getController();
controlMapa.setZoom(13); // de 1 a 21
mapa.setSatellite(true);
mapa.displayZoomControls(true);
// First point
ArrayList<GeoPoint> ap=new ArrayList<GeoPoint>();
latitud = (double) lat1 *1E6;
longitud = (double) long1 *1E6;
loc = new GeoPoint(latitud.intValue(), longitud.intValue());
controlMapa.animateTo(loc);
ap.add(loc);
// Second point
latitud = (double) fichaOtraPersona.getLoc_lan()*1E6;
longitud = (double) fichaOtraPersona.getLoc_lon()*1E6;
loc = new GeoPoint(latitud.intValue(), longitud.intValue());
ap.add(loc);
controlMapa.animateTo(loc);
addPointInTheMap(ap);
} catch (Exception e) {
showToast("Error");
}
}
そして addPointInTheMap メソッド:
private void anadirPuntoEnMapa(ArrayList<GeoPoint> points){
//---Add a location marker---
List<Overlay> listOfOverlays = mapa.getOverlays();
listOfOverlays.clear();
Iterator<GeoPoint> it=points.iterator();
while (it.hasNext()){
MapOverlay mapOverlay = new MapOverlay(getApplicationContext(), mapa, it.next());
listOfOverlays.add(mapOverlay);
}
mapa.invalidate();
}