NRahman NRahman - 4 months ago 72
Android Question

Set Image from drawable as marker in Google Map version 2

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. Any help will be appreciated.

Answer

This is how you can set any 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);
Comments