I'm using Mapbox in my Android app and have custom (black) icons for my markers. Is it possible to change a marker's icon color to something else if it's black?
I can also use a default icon if this is possible with default icons.
Mapbox Android SDK uses a PNG file for the marker icon. You can use any PNG file as an icon, in other words the marker can be just about any color you want. Heres an example with a marker using a custom icon. Heres the code doing most the work:
// Create an Icon object for the marker to use
IconFactory iconFactory = IconFactory.getInstance(MainActivity.this);
Drawable iconDrawable = ContextCompat.getDrawable(MainActivity.this, R.drawable.purple_marker);
Icon icon = iconFactory.fromDrawable(iconDrawable);
// Add the custom icon marker to the map
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(-33.8500000, 18.4158234))
.title("Cape Town Harbour")
.snippet("One of the busiest ports in South Africa")
.icon(icon));
Here are some markers I made using the same style as the default icon:
Place these in your projects drawable-xxhdpi
folder. These are pulled from the Mapbox Android Demo app you can get from the play store
I use this
map.addMarker(new MarkerOptions()
.position(new LatLng(lat,lng))
.icon(IconFactory.getInstance(this).fromResource(R.drawable.ic_marker))
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With