Mostrar siempre el título del marcador de mapa en Android


Estoy agregando el marcador predeterminado al GoogleMap de la siguiente manera:

GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.editMapMap)).getMap();

MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(currentLocation.getCoordinate());
markerOptions.title(Utils.getLocationString(currentLocation.getCoordinate()));
markerOptions.snippet("Blah");

locationMarker = map.addMarker(markerOptions);
locationMarker.setDraggable(true);

¿Cómo puedo hacer que marker muestre siempre el título y el fragmento sin tocar? También me gustaría desactivar ocultarlos al tacto.

Author: Misha, 2013-02-28

5 answers

Es muy fácil:

locationMarker.showInfoWindow();
 84
Author: JerabekJakub,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-22 12:32:45

Hay dos métodos para mostrar y ocultar los marcadores. El valor de retorno booleano simplemente evita que se produzca el comportamiento predeterminado (false) o permite que ocurra (true). En otras palabras, informa al sistema si consumiste el evento o no. Ver Referencia de la API de Google .

private GoogleMap.OnMarkerClickListener onMarkerClickedListener = new GoogleMap.OnMarkerClickListener() {
    @Override
    public boolean onMarkerClick(Marker marker) {
        if (marker.isInfoWindowShown()) {
            marker.hideInfoWindow();
        } else {
            marker.showInfoWindow();
        }
        return true;
    }
};

mGoogleMap.setOnMarkerClickListener(onMarkerClickedListener);
 4
Author: shredder,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-12 20:14:47

Solo devuelve false para onMarkerClickListener, si devuelve true muestra el infoWindow.

Para ocultar el título cuando hacemos clic en el marcador:

map.setOnMarkerClickListener(this);
...

@Override
public boolean onMarkerClick(Marker arg0) {     
  Log.i(TAG,"marker arg0 = "+arg0);               
  return false;
}

Si devolvemos true title se mostrará, de lo contrario si devolvemos false title no se mostrará.

 3
Author: Sandeep Reddy M,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-29 06:58:51

Use showInfoWindow() y agregue el marcador como se muestra a continuación.

Marker marker = mMap.addMarker(new MarkerOptions().position(currentPosition).title("Your text"));
marker.showInfoWindow();
 3
Author: Shailesh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-03 12:56:23

Sé que esta pregunta es antigua, pero publicaré mi respuesta aquí en caso de que ayude a alguien.

Las ventanas de información no funcionarían para mi caso y quería que los títulos se mostraran solo si hay espacio, ocultando potencialmente si no hay suficiente espacio para mostrar para que no se superpongan entre sí.

No encontré ninguna solución en Internet, así que me arremangé e hice esta biblioteca que resuelve mi problema, con suerte ayudará a otros también:

Https://github.com/androidseb/android-google-maps-floating-marker-titles

Aquí hay una vista previa de cómo funciona:

previo

 -1
Author: androidseb,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-12 18:13:57