I'm trying to change the color of markers on Map. I want shape of a common marker but with custom colors. I've tried the following code but it doesn't make any change in color and doesn't give any error as well. Can you please guide any solution or any alternative approach? Any help would be highly appreciated.
Code:
Drawable background = context.getResources().getDrawable(R.drawable.pink_map);
if (background instanceof ShapeDrawable) {
((ShapeDrawable)background).getPaint().setColor(getResources().getColor(R.color.theme_color));
} else if (background instanceof GradientDrawable) {
((GradientDrawable)background).setColor(getResources().getColor(R.color.theme_color));
}
// convert drawable to bitmap
Bitmap bitmap = ((BitmapDrawable) background).getBitmap();
Marker marker = mMap.addMarker(new MarkerOptions().position(sydney)
.title("My Location")
.icon(BitmapDescriptorFactory.fromBitmap(bitmap))
To edit the marker color, click or tap on the marker icon. When you do that, you can change both the color of the marker and its style. Go for the color or style you want to change and then click OK to see the effect. Click on the button labeled Done to save your new marker color settings.
For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.
This is working for me:
mMap.addMarker(new MarkerOptions()
.position(contactLatLng)
.title(contactName)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_map_blue))
);
The important thing is to import the image asset as 'Action Bar and Tab Icons' option. Then you choose the theme CUSTOM and you can select a custom color to apply your image.
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