我想在地图上显示更多点数。我想用“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;
}
答案 0 :(得分:0)
你可以把它们放在一个大小等于arrStatia的数组中。
答案 1 :(得分:0)
使用下面的代码我希望它能运作。
for (Statia s : arrStatia) {
String[] arrCoordonate = s.getCoord().split(",");
GeoPoint point = new GeoPoint((int)(Double.parseDouble(arrCoordonate[0])),(int)(Double.parseDouble(arrCoordonate[1])));
SimpleItemizedOverlay itemizedoverlay = new SimpleItemizedOverlay(
drawable,<<Your Activity name >>.this);
OverlayItem overlayItem = new OverlayItem(point, "xxx", "yyy");
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
<<your map view object>>.postInvalidate();
}