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?
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!
you should use this command .title("\u200e"+"عربی").