3

I created a mobile application which uses Google Maps but I can't seem to make the marker titles display automatically. I always have to tap the marker for its title to appear. Is there any way for the marker title to automatically display once it appears on the map? I want to be able to display the titles of the markers all at once.

melisandre
  • 105
  • 2
  • 6
  • Have a look to this answer, [Show Marker Title](http://stackoverflow.com/a/21717873/4770978). – Adnan Bin Mustafa Nov 21 '16 at 10:14
  • 3
    Possible duplicate of [Always show map marker title in Android](http://stackoverflow.com/questions/15132174/always-show-map-marker-title-in-android) – Volo Nov 21 '16 at 10:15
  • 1
    Thank you. I have several marker titles to display all at once and the .showInfoWindow() only displayed the title of the last marker I added in the ArrayList. – melisandre Nov 21 '16 at 10:37

3 Answers3

6

use showInfoWindow() like below

Marker marker = mMap.addMarker(new MarkerOptions().position(currentPosition).title("Your text"));
marker.showInfoWindow();
masoud vali
  • 1,528
  • 2
  • 18
  • 29
  • 6
    Thank you. It worked but only for one marker. Is it possible to display the titles of the markers on the map all at once? – melisandre Nov 21 '16 at 10:31
  • I don't think so, google won't allow all the infos be open at the same time – masoud vali Nov 21 '16 at 11:04
  • what about having your own custom marker , with your layout , of shape like a InfoWindow , in which you can load different data ?? , google about it @melisandre – Zulqurnain Jutt Nov 21 '16 at 11:37
  • check this : http://stackoverflow.com/questions/14811579/how-to-create-a-custom-shaped-bitmap-marker-with-android-map-api-v2 – masoud vali Nov 21 '16 at 11:41
2

When you are adding your marker on map , just after adding it you have to use marker.showInfoWindow();

below is the example marker adding with window opened:

Marker marker = myMap.addMarker(new MarkerOptions()
                     .position(latLng)
                     .title("Title")
                     .snippet("Snippet")
                     .icon(BitmapDescriptorFactory
                     .fromResource(R.drawable.marker)));

marker.showInfoWindow();
Zulqurnain Jutt
  • 1,083
  • 3
  • 15
  • 41
0

You can use custom xml layout with IconGenerator.

val iconGenerator = IconGenerator(requireContext())

val markerView = LayoutInflater.from(requireContext()).inflate(R.layout.marker, null)
val textView = markerView.findViewById<TextView>(R.id.marker_title_text)

val drawable = ContextCompat.getDrawable(requireContext(), R.drawable.ic_location_marker)

textView.text = "SomeText #1"

iconGenerator.setContentView(markerView)
iconGenerator.setBackground(drawable)

val markerOptions = MarkerOptions()
        .icon(BitmapDescriptorFactory.fromBitmap(iconGenerator.makeIcon()))
        .position(position)
        .anchor(iconGenerator.anchorU, iconGenerator.anchorV)

val marker = map?.addMarker(markerOptions)
Yeldar Nurpeissov
  • 1,786
  • 14
  • 19