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?
After constructing an InfoWindow, you must call open to display it on the map. The user can click the close button on the InfoWindow to remove it from the map, or the developer can call close() for the same effect.
Calling InfoWindow. getOpenedState() returns a boolean which reflects the state (opened/closed) of the infowindow.
Call setPosition() on the info window, or. Attach the info window to a new marker using the InfoWindow. open() method. Note: If you call open() without passing a marker, the InfoWindow will use the position specified upon construction through the InfoWindowOptions object literal.
@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!
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
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