Empty InfoWindow when Marker is clicked

試著忘記壹切 提交于 2019-11-28 00:08:27

问题


This is my code to add new Markers to my GoogleMap:

MarkerOptions m = new MarkerOptions();
m.title(title);
m.snippet(snippet);
m.position(location);
mMap.addMarker(m);

mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            Toast.makeText(DemoActivity.this, "WindowClicked: "+ marker.getTitle() + ":" + marker.getSnippet(),
                    Toast.LENGTH_SHORT).show();
        }
    });

Now This works just fine when my title and snippet are in English. The infoWindow and the Toast works as expected.

However, as in my case, title and snippet are in Arabic, the Toast works fine but the InfoWindow shows empty window.

It seems to me like a bug related to Arabic language. Is there a way to work around it?


回答1:


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




回答2:


@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!




回答3:


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



来源:https://stackoverflow.com/questions/17689311/empty-infowindow-when-marker-is-clicked

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