I am using this part of code to add a marker in a MapFragment in Google Map Version 2.
MarkerOptions op = new MarkerOptions();
op.position(point
@Lukas Novak answer is not showing anything because you also have to set the bounds on Drawable.
This works for any drawable. Here is a fully working example:
public void drawMarker() {
Drawable circleDrawable = getResources().getDrawable(R.drawable.circle_shape);
BitmapDescriptor markerIcon = getMarkerIconFromDrawable(circleDrawable);
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(41.906991, 12.453360))
.title("My Marker")
.icon(markerIcon)
);
}
private BitmapDescriptor getMarkerIconFromDrawable(Drawable drawable) {
Canvas canvas = new Canvas();
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return BitmapDescriptorFactory.fromBitmap(bitmap);
}
circle_shape.xml