I want to make maps with custom markers. In API v2 I can set icon, title, etc for markers. But I want to display title with marker at the first onset. Now title displays only when I taping the marker. In v1 was overlays, but in v2 I didn't found anything similar.
Edited:
Maybe I was not clear enough. Something like Marker.showInfoWindow()
in API works only for one marker. I can't show info windows for all of my markers at the same time. Anyway I need to show titles for all of my markers, without waiting while user will tap on it.
This simple code works to display the title without requiring a click event:
I am not sure which you are trying to achieve: having the info window show up without the user have to tap on the marker, or using a completely different view for the info window (or perhaps both).
To show the info window without requiring a user tap:
I haven't tested this myself, but I'm guessing Marker.showInfoWindow() would do the trick (assuming the Marker's visibility is already
true
.To provide a custom view for the InfoWindow
There are two options here and you should refer to the documentation on GoogleMap.InfoWindowAdapter:
Basically, whether you override
getInfoWindow()
orgetInfoContents()
will depend on whether or not you just wish to customize what you see inside the callout bubble, or whether you wish to customize the entire info window view, including an alternative to the callout bubble.One caveat: I believe when you override these methods, it performs a simple rendering of what the view looks like at the time
getInfoWindow()
orgetInfoContents()
is called. I myself am interested in trying to replicate the look of the native Google Maps Android app which has a little "directions" icon next to the name of the place. One of the problems I believe (see here: https://stackoverflow.com/a/13713536/129475) is that if you have something like a button in your view, it may not behave like a button because of the static rendering.I have also stumbled upon this problem. V2 API is a step forward, two steps back. Google, please add an overridable 'draw' method on the Marker or GoogleMap classes so we can customize the drawing ourselves.
A possible solution is to generate the bitmap on the fly and attach it to the marker. i.e. Create a canvas, insert the marker bitmap, draw the text next to the marker. This involves some painful calculations (the appropriate canvas size with the marker bitmap and the text next to each other). Unfortunately, there's no setIcon method in Marker, so every time the text changes, a new marker has to be created. It may be fine if you just have a marker on the map, but with dozens of markers, this may not be feasible. Also there may be memory issue on creating those bitmaps dynamically. A sample code (with just the text):
Hopefully, Google will add the appropriate methods so we can do this easily. Damn, I really like the new Map rotate feature in V2 API.
Finally did it. So what you do is have a background image (in my case i just use a blue rectangle). Create a marker like so:
Notice the writeTextOnDrawable() Method:
Thanks to Arun George: Add text to image in android programmatically
I solved this problem by making my own markers with a picture editor which has the details below. It took some time to make, but it works.
I used Photoshop and 53x110px markers.
Customize the marker image
You can replace the default marker image with a custom marker image, often called an icon. Custom icons are always set as a BitmapDescriptor, and defined using one of four methods in the BitmapDescriptorFactory class.
fromAsset(String assetName) Creates a custom marker using an image in the assets directory.
fromBitmap (Bitmap image) Creates a custom marker from a Bitmap image.
fromFile (String path) Creates a custom icon from a file at the specified path.
fromResource (int resourceId) Creates a custom marker using an existing resource. The below snippet creates a marker with a custom icon.