我有以下代码从数据库获取信息并在地图上绘制。信息存在且可点击,但实际图标androidmarker
不可见。为什么?我该如何解决这个问题?
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tweets = new LocationData(this);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setSatellite(true);
mc = mapView.getController();
mc.setZoom(17);
mapView.setBuiltInZoomControls(true);
// Add the MyPositionOverlay
positionOverlay = new MyPositionOverlay();
List<Overlay> overlays = mapView.getOverlays();
overlays.add(positionOverlay);
//Add the Mapitems Overlay.
mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
itemizedoverlay = new Mapitems(drawable, this);
mylocation();
distance(lat,lng);
addmark();
mapView.invalidate();
}
public void addmark(){
SQLiteDatabase db = tweets.getWritableDatabase();
String count = "SELECT * FROM tweets;";
Cursor mcursor = db.rawQuery(count, null);
startManagingCursor(mcursor);
mcursor.moveToFirst();
if(mcursor != null && mcursor.moveToFirst())
{
do
{
System.out.println("WHAT");
String tname = mcursor.getString(4);
String tmessage = mcursor.getString(7);
Double tlat = mcursor.getDouble(1);
System.out.println("lat" + tlat);
Double tlng = mcursor.getDouble(2);
System.out.println("lng" + tlng);
GeoPoint point = new GeoPoint(
(int) (tlat*1E6),
(int) (tlng*1E6));
OverlayItem overlayitem = new OverlayItem(point, tname, tmessage);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}while(mcursor.moveToNext());
}
}
答案 0 :(得分:0)
我假设Mapitems是实现ItemizedOverlay的类。
可能存在问题。您可以按照here的说明正确地创建该类。我自己也遵循了这个教程,它对我来说很好。重要的是确保在populate()
addOverlay(OverlayItem overlay)
另外,为什么你有mapOverlays
和overlays
?他们不一样吗?