Can anyone tell me how can I show my current location on OSM map with custom icon?
Asked
Active
Viewed 3,193 times
2
-
I am asking about OSM not google map – Android Guy Nov 03 '17 at 10:11
1 Answers
7
With default person icon:
MyLocationNewOverlay myLocationoverlay = new MyLocationNewOverlay(mapView);
myLocationoverlay.enableFollowLocation();
myLocationoverlay.enableMyLocation();
mapView.getOverlays().add(myLocationoverlay);
With custom icon:
MyLocationNewOverlay myLocationoverlay = new MyLocationNewOverlay(mapView);
myLocationoverlay.enableFollowLocation();
Drawable currentDraw = ResourcesCompat.getDrawable(getResources(), R.mipmap.ic_launcher, null);
Bitmap currentIcon = null;
if (currentDraw != null) {
currentIcon = ((BitmapDrawable) currentDraw).getBitmap();
}
myLocationoverlay.setPersonIcon(currentIcon);
myLocationoverlay.enableMyLocation();
mapView.getOverlays().add(myLocationoverlay);
I am using updated OSM dependency
compile 'org.osmdroid:osmdroid-android:5.6.5'

Flummox - don't be evil SE
- 2,109
- 6
- 24
- 46

Maroof
- 891
- 6
- 7
-
1
-
-
3You should finally set your icon as a person icon `myLocationoverlay.setPersonIcon( currentIcon );` or direction arrow: `myLocationoverlay.setDirectionArrow( personIcon, currentIcon );` – Arash Apr 25 '19 at 09:11
-
Might need this to load a drawable: https://stackoverflow.com/a/10600736/4421627 – Flummox - don't be evil SE Jan 27 '21 at 13:51