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 :-) ... 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 :-( ... I'm a bit stuck any ideas?
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.
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.
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.
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; } });
I added a feature request here: http://code.google.com/p/gmaps-api-issues/issues/detail?id=7652
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With