1
所以我有一個mapView,我想基於數據庫動態填充它。我所能做的每一個的GeoPoint indidivually但由於某些原因,當我嘗試做所有這些不顯示在地圖上的點。如果任何人有任何建議,請讓我知道:-)在android中動態填充地圖
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());
}
}
}
此代碼將顯示'fieldTripStops'中的所有內容。如果你沒有看到所有的點,那麼'fieldTripStops'沒有你想象的那樣。 – CommonsWare