0

I'm implementing an Uber clone app and I'm using the Google Maps Api.

I wanted to add some marker to the map, except I don't want it to have an icon, just a label showing the estimated time till arrival. Any idea how can I achieve that?

I tried to set the icon to null, but when I did that my title didn't show either!

1 Answers1

1

What you need to do is make a String into an Icon which is then displayed just like an icon which then appears as a label.

So to create a BitMapDescriptor (for the icon) from text:

IconGenerator icg = new IconGenerator(this);
icg.setColor(Color.GREEN);
icg.setTextAppearance(R.style.TextAppearance_AppCompat_Small);
Bitmap bm = icg.makeIcon("ETA: 3m");
markerOpts.icon(BitmapDescriptorFactory.fromBitmap(bm));

// set position and other props on markerOpts and add
mMap.addMarker(markerOpts);

Note the title property can also be added if desired (but not necessary) and works as you'd expect - click on icon and title is displayed.

And you can also update the icon (with new ETA) at any time by using the Marker object and set the icon as above.

There's other approaches discussed here (which is where the above snippet came from): Map Markers with text in Google Maps Android API v2.


Initial Marker Display:

enter image description here

And with title after clicking:

enter image description here