I'm writing a map-based app on Android using Maps API v2.
I already have markers being placed on the map, and can display custom info windows for those markers, but AFAICT only one info window can be displayed at a time. There are a couple of spots where I want different behaviour: I want to always display the info window for multiple windows, without a marker showing.
I suppose I could write some code to draw the info windows to bitmap-backed canvases and pass those bitmaps to the map as marker "icons". This kind of sums up what I'm trying to do quite well: I want the info windows to be my markers. But this approach would require me to write my own window frame drawing code which I'd rather avoid.
Is there a better way of supporting more than one info window being displayed at once?
An InfoWindow displays content (usually text or images) in a popup window above the map, at a given location. The info window has a content area and a tapered stem. The tip of the stem is attached to a specified location on the map.
An InfoWindow can be placed on a map at a particular position or above a marker, depending on what is specified in the options. Unless auto-pan is disabled, an InfoWindow will pan the map to make itself visible when it is opened. After constructing an InfoWindow, you must call open to display it on the map.
In the docs it states:
Since there is only one info window shown at any one time, this provider may choose to reuse views, or it may choose to create new views on each method invocation.
So no you can't do it with the regular infoviews but it isn't too hard creating markers that act as infoviews.
Edit
I'd create a view in xml that you want to use as a marker/dialog. Something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="100dp"
android:orientation="vertical"
android:background="@android:color/white"
>
<TextView
android:text="test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="50dp"
android:layout_height="50dp"/>
</LinearLayout>
Then I'd convert this view into a bitmap and use that bitmap as my marker:
ImageView image = (ImageView) findViewById(R.id.main_image);
LinearLayout tv = (LinearLayout) this.getLayoutInflater().inflate(R.layout.test_layout, null, false);
tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
tv.setDrawingCacheEnabled(true);
tv.buildDrawingCache();
Bitmap bm = tv.getDrawingCache();
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