1

所以我有一个 mapView,我想根据数据库动态填充它。我可以单独完成每个地理点,但由于某种原因,当我尝试全部完成时,它不会在地图上显示这些点。如果有人有建议,请告诉我:-)

public class FieldTrip extends MapActivity {
  private MapView map=null;
  private MyLocationOverlay me=null;
  private String theLat;
  private String theLong;
  private Double theDLat;
  private Double theDLong;


  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maptastic);

    map=(MapView)findViewById(R.id.mapView);

    map.getController().setCenter(getPoint(40.76793169992044,
                                            -73.98180484771729));
    map.getController().setZoom(17);
    map.setBuiltInZoomControls(true);

    Drawable marker=getResources().getDrawable(R.drawable.supaaaa);

    marker.setBounds(0, 0, marker.getIntrinsicWidth(),
                            marker.getIntrinsicHeight());

    map.getOverlays().add(new SitesOverlay(marker));

    me=new MyLocationOverlay(this, map);
    map.getOverlays().add(me);
  }

  @Override
  public void onResume() {
    super.onResume();

    me.enableCompass();
  }   

  @Override
  public void onPause() {
    super.onPause();

    me.disableCompass();
  }   

  @Override
  protected boolean isRouteDisplayed() {
    return(false);
  }

  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_S) {
      map.setSatellite(!map.isSatellite());
      return(true);
    }
    else if (keyCode == KeyEvent.KEYCODE_Z) {
      map.displayZoomControls(true);
      return(true);
    }

    return(super.onKeyDown(keyCode, event));
  }

  private GeoPoint getPoint(double lat, double lon) {
    return(new GeoPoint((int)(lat*1000000.0),
                          (int)(lon*1000000.0)));
  }






private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
    private List<OverlayItem> items=new ArrayList<OverlayItem>();

    ///need to make this dy-NAMIK :p
    public SitesOverlay(Drawable marker) {
      super(marker);


      for (Entry<Integer, FieldTripStop> cur : Statics.fieldTripStops.entrySet())
        {
            // get the FieldTripStop object from the current hash table entry
            Statics.currentFTStop = cur.getValue();
            // concatenate numbers before (all) and after (6) the decimal, since
            // geopoints only accept 6 numbers past the decimal.
            theLat = Statics.currentFTStop.latitude;
            theLong = Statics.currentFTStop.longitude;
            theDLat = Double.parseDouble(theLat);
            theDLong = Double.parseDouble(theLong);

      boundCenterBottom(marker);

      items.add(new OverlayItem(getPoint(theDLat,
              theDLong),
                                "RANDOM TEXT?",
                                "RANDOM TEXT LALALA"));


        }
      populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
      return(items.get(i));
    }

    @Override
    protected boolean onTap(int i) {
      Toast.makeText(FieldTrip.this,
                      items.get(i).getSnippet(),
                      Toast.LENGTH_SHORT).show();

      return(true);
    }

    @Override
    public int size() {
      return(items.size());
    }
  }
}
4

1 回答 1

1

这段代码对我来说是正确的。如果您没有看到所有的点,那么fieldTripStops就没有您希望显示的所有点。仔细检查集合中的元素fieldTripStops

于 2012-05-19T23:52:38.143 回答