地図上により多くのポイントを表示したい。それを「for」でやりたい。私の問題は、変数 point と overlayItem が毎回上書きされるため、最後のポイントのみが表示されることです。この変数に一意の名前を付けるにはどうすればよいですか?
List<Statia> arrStatia = datasourceStatia.getAllStatias();
for (Statia s : arrStatia) {
String[] arrCoordonate = s.getCoord().split(",");
GeoPoint point = new GeoPoint((int)(Double.parseDouble(arrCoordonate[1])),(int)(Double.parseDouble(arrCoordonate[0])));
OverlayItem overlayItem = new OverlayItem(point, Double.parseDouble(arrCoordonate[1]) + "", Double.parseDouble(arrCoordonate[0]) +"");
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
mapView.postInvalidate();
Log.v("xxx", s.getCoord());
}
public class Statia {
private long id;
private String statia;
private long idruta;
private String coord;
private String program;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getIdRuta() {
return idruta;
}
public void setIdRuta(long idruta) {
this.idruta = idruta;
}
public String getStatia() {
return statia;
}
public void setStatia(String statia) {
this.statia = statia;
}
public void setCoord(String coord) {
this.coord = coord;
}
public String getCoord() {
return coord;
}
public void setProgram(String program) {
this.program = program;
}
public String getProgram() {
return program;
}
// Will be used by the ArrayAdapter in the ListView
@Override
public String toString() {
return statia;
}
}
public List<Statia> getAllStatias() {
List<Statia> statias = new ArrayList<Statia>();
Cursor cursor = database.query(DatabaseHelper.statiiTable,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Statia statia = cursorToStatia(cursor);
statias.add(statia);
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
return statias;
}
private Statia cursorToStatia(Cursor cursor) {
Statia statia = new Statia();
statia.setId(cursor.getLong(0));
statia.setStatia(cursor.getString(1));
statia.setIdRuta(cursor.getInt(2));
statia.setCoord(cursor.getString(3));
statia.setProgram(cursor.getString(4));
return statia;
}