Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OsmDroid show current LocationIcon not working

I'm using OSMDroid in my Android App. Everything works fine except I can not display the Icon to show my current Location. Following my Code:

openMapView = (org.osmdroid.views.MapView) v.findViewById(R.id.openmapview);
openMapView.setClickable(true);

openMapView.setMultiTouchControls(true);
final float scale = getResources().getDisplayMetrics().density;
final int newScale = (int) (256 * scale);
String[] OSMSource = new String[2];
OSMSource[0] = "http://a.tile.openstreetmap.org/";
OSMSource[1] = "http://b.tile.openstreetmap.org/";
XYTileSource MapSource = new XYTileSource(
    "OSM",
    null,
    1,
    18,
    newScale,
    ".png",
    OSMSource
);
openMapView.setTileSource(MapSource);
mapController = (MapController) openMapView.getController();
mapController.setZoom(14);

// My Location Overlay
myLocationoverlay = new MyLocationOverlay(getActivity(), openMapView);
myLocationoverlay.enableMyLocation(); // not on by default
myLocationoverlay.enableCompass();
myLocationoverlay.disableFollowLocation();
myLocationoverlay.setDrawAccuracyEnabled(true);

myLocationoverlay.runOnFirstFix(new Runnable() {
    public void run() {
        mapController.animateTo(myLocationoverlay.getMyLocation());
    }
});

Can anyone give my an idea where I am going wrog and what I should change in my code.

like image 373
Mojo Avatar asked Dec 02 '25 06:12

Mojo


1 Answers

To enable MyLocationOverlay you need to call:

myLocationoverlay.enableMyLocation();
mMapView.getOverlays().add(mMyLocationNewOverlay);

In addition remove this line from you code:

myLocationoverlay.disableFollowLocation();
like image 195
Ziem Avatar answered Dec 03 '25 19:12

Ziem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!