Display toolbar for Google Maps marker automatical

2020-01-27 02:40发布

I have a marker and when I open the map it shows the marker. When I click on it it shows the title and a toolbar which includes two buttons on the bottom right of the map which let me launch intents to navigate to the marker or show it in google maps. I would like to have these displayed automatically when the map is opened rather than having the user to click on the marker.

Like this :-) ... enter image description here I can't seem to work out how to do this.

I have tried:

// create marker
MarkerOptions marker = new MarkerOptions().position(
        new LatLng(latitude, longitude)).title("title");

// adding marker
googleMap.addMarker(marker).showInfoWindow();
googleMap.getUiSettings().setMapToolbarEnabled(true);

But this just shows the marker title and a button on the top right to go to my location not the two toolbar intent buttons on the bottom right.

Like this :-( ... enter image description here I'm a bit stuck any ideas?

7条回答
Melony?
2楼-- · 2020-01-27 03:14

if i'm not mistaken you want to show the two buttons that related to the marker on the right botton side of the map and those buttons has some dependency to the marker if i'm true so you just need tu implement a new method like code below and just call this method on create and sure in your marker click listener

@Override
public void markerIntentButtonShow(Marker marker) {
      //setvisible(true) to your side buttons or call some Intent
      Intent i = new Intent(getActivity(), MarkerViewDetails.class);
      i.putExtra("marker_snippet", marker.getSnippet());
      startActivity(i);
}

and call the method in your click listener

        googleMap
                .setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

                    @Override
                    public void onInfoWindowClick(Marker marker) {

                            markerIntentButtonShow(marker);
                    }
                });

and in your onCreateView

MarkerOptions marker = new MarkerOptions().position(
        new LatLng(latitude, longitude)).title("title");
googleMap.addMarker(marker).showInfoWindow();
markerIntentButtonShow(marker);
查看更多
登录 后发表回答