سؤال

I got some problem here. I use osmdroid to display maps and I need some functions like add map marker and draw a path between markers.

For adding markers on map I use this instructions

// Global declaration
ArrayList<OverlayItem> world_overlay; 
ItemizedIconOverlay<OverlayItem> world_items;
MapController citymap_controller;

// this code is in function
world_overlay = new ArrayList<OverlayItem>();
for(int i = 0; i < States.length; ++i)
{
    GeoPoint cur_geo = new GeoPoint(latitude[i], longtitude[i]);
    OverlayItem cur_item = new OverlayItem(States[i], States[i], cur_geo);
    world_overlay.add(cur_item);
}

world_items = new ItemizedIconOverlay<OverlayItem>(this, world_overlay, null);
mapView.getOverlays().add(world_items); 

but I got some strange thing. If i use this snippet in function onCreate it works fine all markers are added. If I use this code in click handler of button on main screen it doesn't work. Program continues running without any problem, but markers are not displayed. This handler is implemented because other instructions are work fine. The problem is only in displaying markers. Does someone know what's wrong?

هل كانت مفيدة؟

المحلول

add marker and next

mapView.invalidate();

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top