Android Guy
Android Guy

Reputation: 583

OSM - Show current location with custom icon

Can anyone tell me how can I show my current location on OSM map with custom icon?

Upvotes: 2

Views: 3599

Answers (1)

Maroof
Maroof

Reputation: 891

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'

Upvotes: 7

Related Questions