1

I am trying to change the overlay icon for MyLocationNewOverlay using the setPersonIcon (bitmap) method but the marker still appears with the default icon.

Sharing the code I am using from OSM - Show current location with custom icon below:

    mLocationOverlay.enableMyLocation();

     Drawable currentDraw = ResourcesCompat.getDrawable(getResources(), R.drawable.joker, null);
     Bitmap currentIcon = null;
     if (currentDraw != null) {
         currentIcon = ((BitmapDrawable) currentDraw).getBitmap();
     }
     mLocationOverlay.setPersonIcon(currentIcon);
     mLocationOverlay.enableFollowLocation();


     map.getOverlays().add(mLocationOverlay);

I am running this on an AVD on mac os 10.15 public beta

Based on a comment on an open issue on osmdroid github page i also tried Genymotion, but the behaviour on that was even more weird with none of the overlays except scaleoverlay working on genymotion emulator, nether setting zoom level in code.

I haven’t yet tried the code on an actual android device

UPDATE: When trialing the app while driving I realized that the customer PersonIcon appeared whenever I was stationary and switched to the white arrow when moving. This lead me back to the documentation and realized that had to also update the person icon while moving using the setDirectionArrow method.

nebula_007
  • 171
  • 1
  • 2
  • 13
  • Appears to work on my LG v20 (physical device) sometimes though, on location refresh it switches back and forth between the standard marker and custom marker. – nebula_007 Sep 12 '19 at 11:33

1 Answers1

0

Yes you got it right you have to use setDirectionArrow.

    myLocationoverlay.setDirectionArrow( currentIcon, currentIcon );
    myLocationoverlay.setPersonIcon( currentIcon );
Sagar Dangi
  • 161
  • 4