Adding Overlay to MapView in osmdroid

I am writing a simple Android application using osmdroid, working offline offline until I can display the map (online and offline), and I want to add overlay (markers) to the map, I had a simple example of using an overlay in osmdroid and I tried some of them, but they didn’t work, so I need any example of adding an overlay or marker using osmdroid

+6
source share
2 answers

Take a look at the ItemizedIconOverlay class.

Here are some examples on the Internet when searching, for example, an example was posted in Stack Overflow: Adding Overylay to OSMDROID

+2
source
public class mapcode extends Activity { globalvar appState; int stats=0; private MapView mapView; private IMapController mapController; private SimpleLocationOverlay mMyLocationOverlay; private ScaleBarOverlay mScaleBarOverlay; ItemizedIconOverlay<OverlayItem> currentLocationOverlay; DefaultResourceProxyImpl resourceProxy; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.map); appState = ((globalvar) getApplicationContext()); mapView = (MapView) this.findViewById(R.id.mapview); mapView.setTileSource(TileSourceFactory.MAPNIK); // mapView.setBuiltInZoomControls(true); // ZOOM +- mapView.setMultiTouchControls(true); mapController = this.mapView.getController(); mapController.setZoom(2); this.mMyLocationOverlay = new SimpleLocationOverlay(this); this.mapView.getOverlays().add(mMyLocationOverlay); this.mScaleBarOverlay = new ScaleBarOverlay(this); this.mapView.getOverlays().add(mScaleBarOverlay); ///////////////// resourceProxy = new DefaultResourceProxyImpl(getApplicationContext()); GeoPoint currentLocation = new GeoPoint(55.860863,37.115046); GeoPoint currentLocation2 = new GeoPoint(55.8653,37.11556); OverlayItem myLocationOverlayItem = new OverlayItem("Here", "Current Position", currentLocation); Drawable myCurrentLocationMarker = this.getResources().getDrawable(R.drawable.a); myLocationOverlayItem.setMarker(myCurrentLocationMarker); final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>(); items.add(myLocationOverlayItem); myLocationOverlayItem = new OverlayItem("Here", "Current Position", currentLocation2); myCurrentLocationMarker = this.getResources().getDrawable(R.drawable.a); myLocationOverlayItem.setMarker(myCurrentLocationMarker); items.add(myLocationOverlayItem); currentLocationOverlay = new ItemizedIconOverlay<OverlayItem>(items, new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() { public boolean onItemSingleTapUp(final int index, final OverlayItem item) { return true; } public boolean onItemLongPress(final int index, final OverlayItem item) { return true; } }, resourceProxy); this.mapView.getOverlays().add(this.currentLocationOverlay); 

mapView.invalidate (); // for markers to appear}

+1
source

Source: https://habr.com/ru/post/914145/


All Articles