0

I'm trying to add ImageVector icons I have (created as, for example, Icons.Default.Home) to Markers in Google Maps. What I currently have is this:

val opt = MarkerOptions()
opt.position(LatLng(lat, lng))          // lat and lng are defined above
opt.title(title)                        // title as well
opt.icon(BitmapDescriptorFactory.?????) // and there the problem occurs.

What I found out it that BitmapDescriptorFactory can create the requested BitmapDescriptor by passing a resource or a bitmap (respectively BitmapDescriptorFactory.fromResource(resourceId: Int) and BitmapDescriptorFactory.fromBitmap(image: Bitmap)).

The problem is I cannot find out how to convert the ImageVector I got from Icons.Default.Home to any of the above. I found some questions on the Stack about converting a vector drawable to a bitmap, but still, none of them covers the problem with converting ImageVector. I also checked if the instance of ImageVector has any potentially helpful methods, but it can only - if I'm not mistaken - convert it to a String, which is totally useless in my case.

Any help will be highly appreciated

Amvix
  • 143
  • 3
  • 9

1 Answers1

0

Ok, I think I somehow made it with a (not so) dirty trick. I downloaded the icons I needed from Google Material Icons site (https://fonts.google.com/icons?selected=Material+Icons) and imported them into my project. Later I used a snippet provided by @Leo Droidcoder here: Custom marker in google maps in android with vector asset icon to use these icons as markers.

This way I have markers that look like the icons I wanted, but I believe there must be a better solution.

Amvix
  • 143
  • 3
  • 9