How to put more information in the window when clicking on a Marker?

1

When you open the map, in MainActivity, I display some pins on the screen (markerOptions), as shown below:

WAPIService.getInstance().getPontosMapeamento(latitude, longitude, new FutureCallback<List<MapPins>>() {

                    @Override
                    public void onSuccess(List<MapPins> result) {
                        for (MapeamentoColaborativo mapPin : result){
                            showMapPins(mapPin.getLat_Pino(),mapPin.getLng_Pino(),mapPin.getPino(),mapPin.getAddress());//getAddress no formato para exibicao
                        }
                    }

                    @Override
                    public void onFailure(Throwable throwable) {
                        Toast.makeText(activity.getApplicationContext(), "Ocorreu algum problema", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });

showMapPins:

...
protected GoogleMap map;
...
private void showMapPins(double lat, double lng, String pin, String address) {
    LatLng location = new LatLng(lat, lng);
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(location);
    switch (pin) {
        case "1":
            map.addMarker(new MarkerOptions().position(location).title("Marker1").icon(BitmapDescriptorFactory.fromResource(R.drawable.mk_one)));//TODO exibir endereço
            break;
        case "2":
            map.addMarker(new MarkerOptions().position(location).title("Marker2").icon(BitmapDescriptorFactory.fromResource(R.drawable.mk_two)));
            break;
        case "3":
            map.addMarker(new MarkerOptions().position(location).title("Marker3").icon(BitmapDescriptorFactory.fromResource(R.drawable.mk_three)));
            break;
        case "4":
            map.addMarker(new MarkerOptions().position(location).title("Marker4").icon(BitmapDescriptorFactory.fromResource(R.drawable.mk_four)));
            break;
        case "5":
            map.addMarker(new MarkerOptions().position(location).title("Marker5").icon(BitmapDescriptorFactory.fromResource(R.drawable.mk_five)));
            break;
        case "6":
            map.addMarker(new MarkerOptions().position(location).title("Marker6").icon(BitmapDescriptorFactory.fromResource(R.drawable.mk_six)));
            break;
    }
}

How can I put this address as a "subtitle" to appear when I click the marker on the map? .title ("Marker1 \ n" + address) - > does not work.

    
asked by anonymous 16.05.2017 / 00:30

1 answer

1

If you just want to add a string below the Marker title use MarkerOptions # snippet (String snippet) .

map.addMarker(new MarkerOptions().position(location)
                                 .title("MarkerX")
                                 .snippet(address)
                                 .icon(BitmapDescriptorFactory.fromResource(R.drawable.mk_six)));

It is, however, possible to completely customize the contents of the Marker information window. To do this, you need to create a full implementation of the InfoWindowAdapter interface. and call map.setInfoWindowAdapter() with your implementation.
For more information, see Information windows in the documentation.

    
17.05.2017 / 16:03