Empty InfoWindow when Marker is clicked

别来无恙 提交于 2019-11-29 06:42:26

A way around this would be to show a custom info window. You can do this by creating a InfoWindowAdapter and setting it with GoogleMap.setInfoWindowAdapter().

To replace the default info window, override getInfoWindow(Marker) with your custom rendering and return null for getInfoContents(Marker). To replace only the info window contents inside the default info window frame (the callout bubble), return null in getInfoWindow(Marker) and override getInfoContents(Marker) instead.

More Info: https://developers.google.com/maps/documentation/android/marker#info_windows

@jimmithy answer solved my question.

This is just a three-step implementation of it from this project:

Step 1: Create the layout of your infoWindow. Here is popup.xml code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="2dip"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/icon"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textStyle="bold"/>

<TextView
android:id="@+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"/>
</LinearLayout>

</LinearLayout>

Step 2: Create your implementation of InfoWindowAdapter. Here is PopupAdapter class:

class PopupAdapter implements InfoWindowAdapter {
  LayoutInflater inflater=null;

  PopupAdapter(LayoutInflater inflater) {
    this.inflater=inflater;
  }

  @Override
  public View getInfoWindow(Marker marker) {
    return(null);
  }

  @Override
  public View getInfoContents(Marker marker) {
    View popup=inflater.inflate(R.layout.popup, null);

    TextView tv=(TextView)popup.findViewById(R.id.title);

    tv.setText(marker.getTitle());
    tv=(TextView)popup.findViewById(R.id.snippet);
    tv.setText(marker.getSnippet());

    return(popup);
  }
}

Step 3: In your Activity, set your adapter to the GoogleMap:

mMap.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater()));

And you are set!

Morteza safari

you should use this command .title("\u200e"+"عربی").

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!