开发者

Marker icon not showing up but is clickable

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

    }
}


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜