0

我想在地图上显示更多点。我想用“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;
}
4

2 回答 2

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();    

}
于 2012-05-28T08:43:43.100 回答
0

您可以将它们放入大小等于 arrStatia 的数组中。

于 2012-05-28T08:30:39.910 回答