Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 806
samleighton87 Avatar asked Dec 29 '14 14:12

samleighton87


People also ask

How do I get a marker position on Google Maps?

You can add a simple marker to the map at a desired location by instantiating the marker class and specifying the position to be marked using latlng, as shown below.

What is the Google map marker called?

The Google Maps pin is the inverted-drop-shaped icon that marks locations in Google Maps. The pin is protected under a U.S. design patent as "teardrop-shaped marker icon including a shadow". Google has used the pin in various graphics, games, and promotional materials.

How do you refresh a marker on Google Maps?

To reload the markers, when you create then, push them to an array. Then create a function where you iterate through the array, setting the markers map as null. After this, erase the array.


2 Answers

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;     } }); 
like image 170
Simas Avatar answered Oct 11 '22 00:10

Simas


I added a feature request here: http://code.google.com/p/gmaps-api-issues/issues/detail?id=7652

like image 43
rockgecko Avatar answered Oct 11 '22 00:10

rockgecko