I have a problem with marker on google maps api v2. I would like to customize infoWindows with a WebView:
Here my code of InfoWindowAdapter
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker arg0) {
View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);
TextView title = (TextView) v.findViewById(R.id.title_marker);
WebView snippet = (WebView) v.findViewById(R.id.item_snippet);
title.setText(arg0.getTitle());
snippet.setVisibility(WebView.VISIBLE);
snippet.loadData(arg0.getSnippet(),"text/html", "UTF-8");
return v;
}
});
And this is the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/title_marker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<WebView
android:id="@+id/item_snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
My problem is that I see the content into the TextView, but not the content into the WebView. What i'm doing wrong? Thanks a lot
You can't use a WebView directly. The reason is (source: official docs):
You can try drawing the webview on a bitmap (after the content has been loaded) and supplying an
ImageView
with that bitmap in theInfoWindow
adapter, but you will lose interactivity with the webview anyway.after a lot of tests, googling and some reversing I can say that view you return in
getInfoContents
is used to render into aBitmap
and then hidden. Thebitmap
is then displayed viaGL
I've found a workaround that can be fine for you.
in this example I've used the snippet to store the url, It's not exactly what did you asked, but it may look similar.
Edit: the first version was recycling the
WebView
but it's not possible without some trick to remove it from theAlert
, this revised version doesn't shows theInfoContents
box below but has still an issue, when pressed it keeps a sort of state, and it believes the marker is clicked after closing the dialog.You may use a layout that contains a
WebView
to decor a bit the windowEdit2: Reverted to something like the first version, a blank
InfoContents
box shows for bit I'm not sure it's avoidable.