Google android maps api v2 Show Marker Title Always
Solution 1
Just call Marker.showInfoWindow();
. See https://developers.google.com/maps/documentation/android/marker#info_windows and https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Marker#showInfoWindow()
Solution 2
Something like that:
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title("Your position")).showInfoWindow();
Solution 3
You can do this:
Marker marker = mMap.addMarker(new MarkerOptions().position(currentPosition).title("Your text"));
marker.showInfoWindow();
Solution 4
For displaying marker titles on the map around the markers, none of the solutions I found on internet worked for me so I rolled up my sleeves and made this library which solves this problem for me, hopefully it will help others too:
https://github.com/androidseb/android-google-maps-floating-marker-titles
Here is a preview of how it works:
Solution 5
I'm not so good in some implementation but here is my code:
public BitmapDescriptor getBitmapFromView(String title) {
View view = LayoutInflater.from(activity.getApplicationContext()).inflate(R.layout.marker_tooltip, null);
((TextView) view.findViewById(R.id.tooltips_title)).setText(title);
//Get the dimensions of the view. In my case they are in a dimen file
int width = activity.getResources().getDimensionPixelSize(R.dimen.tooltips_width);
int height = activity.getResources().getDimensionPixelSize(R.dimen.tooltips_height);
int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
view.measure(measuredWidth, measuredHeight);
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return BitmapDescriptorFactory.fromBitmap(bitmap);
}
...
marker.setIcon(getBitmapFromView(marker.getTitle()));
...
I implemented this in a fragment in a map app with some variations. For example, with a custom Info Window and some events on the map but its implementation was required to show all marker title at the same time. Let me know if it was helpful for you too
the ACTIVITY of "activity.getResources().getDimensionPixelSize(R.dimen.tooltips_width)" variable is a property in the fragment
Related videos on Youtube
Comments
-
Sercan Ozdemir almost 4 years
I have a google maps v2 in my android application and some markers on it. When user click one of these markers, a title popup comes. How can I show these titles always without user click?
-
Sercan Ozdemir about 11 yearsThank you it helpmed me a bit. But i want to show all titles at same time. Is it possible ?
-
Makvin over 6 yearsits work completely when default info window is use but when i use Info window adapter for custom info window than how to info window default open??
-
Myat Min Soe over 5 yearsI don't know why it was downvoted. It's a very useful answer. Thanks for the gif also.
-
Рома Богдан almost 5 yearsThanks man! Also, to measure width of text, you can use textView.paint.measureText(title) to make bitmap width depend on content