-1

I have a SGV icon (.svg) that I want to use like cutom icon for map markers.

How should I proceed ? I didn't find anything on the subject.

Mohamed Jihed Jaouadi
  • 1,427
  • 4
  • 25
  • 44
  • 2
    You probably first need to create a "vector asset" from the SVG file [as instructed in Android documentation](https://developer.android.com/studio/write/vector-asset-studio#running). – Markus Kauppinen Feb 24 '20 at 14:13

1 Answers1

1

If the SVG is part of your resources, you could simply add it to MarkerOptions by calling

val svgIcon = BitmapDescriptorFactory.fromResource(R.drawable.your_svg_name_here)
val marker = MarkerOptions().position(LatLng(latitude, longitude)).icon(svgIcon)
googleMap?.addMarker(marker)

If it isn't in your resources, just use another method of the BitmapDescriptorFactory.

Zholoth
  • 86
  • 3
  • I actually did, but it is not recognized like a valid file extension for drawable folder (accept only .png or .xml) – Mohamed Jihed Jaouadi Feb 24 '20 at 14:02
  • 1
    You could import the svg as a XML-drawable (just right-click on resurces folder and add new vector asset) – Zholoth Feb 25 '20 at 15:08
  • You can't use vector images as map markers as far as I know. The BitmapDescriptorFactory, as its name suggests, only supports bitmaps. – Asim Jul 03 '23 at 20:54