Search code examples
androidlocationoverlayosmdroidmylocationoverlay

Get MyLocationOverlay from osmdroid MapView


Im creating an app where you can toggle the FollowLocation on and off using MyLocationOverlay.

My problem is, when i've already set the MyLocationOverlay earlier, and want to turn on the FollowLocation, but i cant seem to find/get the MyLocationOverlay object in the MapView's OverlayManager. The OverlayManager seems to only return an Overlay object, not the MyLocationOverlay object.

This is how i add the MyLocationOverlay:

main_mapView = (MapView) findViewById(R.id.main_mapView);   
MyLocationOverlay mMyLocationOverlay = new MyLocationOverlay(mContext, main_mapView);
mMyLocationOverlay.enableMyLocation();
mMyLocationOverlay.enableCompass();
mMyLocationOverlay.main_mapView.getOverlays().add(mMyLocationOverlay);
main_mapView.invalidate();

Later i would like to find the MyLocationOverlay doing something like this, but as mentioned it returns an Overlay object.

MyLocationOverlay mMyLocationOverlay = main_mapView.getOverlayManager().get(i);
mMyLocationOverlay.enableFollowLocation()

Anyone?


Solution

  • Just keep a reference to the MyLocationOverlay you new initaly... No need to get it back from the overlay manager.