Set Image from drawable as marker in Google Map version 2

NRahman picture NRahman · Aug 5, 2013 · Viewed 88.1k times · Source

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)
    .title(Location_ArrayList.get(j).getCity_name())
    .snippet(Location_ArrayList.get(j).getVenue_name())
    .draggable(true);
m = map.addMarker(op); 
markers.add(m);

I want to use different images from my drawable.

Answer

Muhammad Babar picture Muhammad Babar · Aug 5, 2013

This is how you can set a Drawable as a Marker.

BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.current_position_tennis_ball)

MarkerOptions markerOptions = new MarkerOptions().position(latLng)
         .title("Current Location")
         .snippet("Thinking of finding some thing...")
         .icon(icon);

mMarker = googleMap.addMarker(markerOptions);

VectorDrawables and XML based Drawables do not work with this.