Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

android - Display toolbar for Google Maps marker automatically

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The overlay that appears when a marker is clicked, is created and destroyed on-the-spot implicitly. You can't manually show that (yet).

If you must have this functionality, you can create an overlay over your map with 2 ImageViews, and call appropriate intents when they're clicked:

// Directions
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
        "http://maps.google.com/maps?saddr=51.5, 0.125&daddr=51.5, 0.15"));
startActivity(intent);
// Default google map
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
        "http://maps.google.com/maps?q=loc:51.5, 0.125"));
startActivity(intent);

Note: you need to change the coordinates based on Marker's getPosition() and the user's location.

Now to hide the default overlay, all you need to do is return true in the OnMarkerClickListener. Although you'll lose the ability to show InfoWindows and center camera on the marker, you can imitate that simply enough:

mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
    @Override
    public boolean onMarkerClick(Marker marker) {
        marker.showInfoWindow();
        mMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
        return true;
    }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...