views:

23

answers:

1

I've got the following code which gets information from a database and plots it on a map. The information is there and clickable but the actual icon androidmarker is not visable. Why? How do I fix this?

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

    }
}
A: 

I'm assuming Mapitems is the class that is implementing ItemizedOverlay. The problem is probably there.You can follow the instructions here on how to create that class properly. I've followed this tutorial myself and it worked fine for me. The important part is to make sure you call populate() after you add the overlay in addOverlay(OverlayItem overlay)

Also, why do you have mapOverlays and overlays? Aren't they the same?

Itsik
I am following that tutorial. I had it working too but now that I'm doing it within a loop it's not showing icons. I've got both just because that's the way I happened to code 2 different Overlays.
Ulkmun
Is the popup box an event of the overlay or you added different markers some place else? Because if you say that it used to work the only logical thing would be that the locations aren't correct
Itsik