Non-ASCII title for android map marker

2019-04-13 07:00发布

问题:

I would like to be able to add a marker with a title that has only non-ASCII characters:

        marker = map.addMarker(
            new MarkerOptions()
                .title("אני")
                .position(latlng)
        );

Unfortunately the tile doesn't show up, only an empty info window. First I thought that there is a problem with the Hebrew characters in general, but they seem to be fine, because if there's ASCII text in the BEGINNING of the title, then it works:

                .title("me אני")

However it doesn't when the Hebrew is in the beginning:

                .title("אני me")

回答1:

I found a hack that seems to work, but still waiting for a real solution.

If I prepend an unicode left-to-right mark to the title, it seems to work no matter if the 1st character is rtl or ltr:

.title("\u200e" + "אני me")


回答2:

Use a customized InfoWindowAdapter, and set a layout there as you see fit.

Do note that using LinearLayout in the customized InfoWindowAdapter would cause this issue too (which is weird).

Try RelativeLayout instead, or, if you have API 17 and above, set textDirection for each of the TextViews, and it should work