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

Asked

Viewed 166 times

1

When opening the map, in Mainactivity, I display some pins on the screen (markerOptions), as codes 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 set this address as a "sub-title" to appear when clicking the marker on the map? . title("Marker1 n"+address) -> does not work.

1 answer

1


If what you want is just to add a string underneath 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 fully customize the contents of the Marker information window.
For this, it is necessary to create a complete implementation of the interface Infowindowadapter and call map.setInfoWindowAdapter() with its implementation.
For more information see Information windows, in the documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.