Google Maps Android API v2, Marker title/snippet wrong display

后端 未结 3 2229

I use Google Maps Android API v2 with Android to show current position with nearby markers. Nearby places locations and titles are received using Google Places API.

The

相关标签:
3条回答
  • 2021-02-16 00:14

    I've noticed that this bug occurs only on LinearLayout (which is very weird).

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

    0 讨论(0)
  • 2021-02-16 00:30

    Adding more info regarding CommnsWare answer:

    As of the moment I am writing this commend, it seems that the map itself is layout_direction="LTR" which means that your titles will not be flipped on RTL desktops. The solution is simple:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:layoutDirection="locale"
    >
        ....
    </RelativeLayout>
    

    Note that I am using the locale's layout direction and not the inherited direction. I commented this on the corresponding Google bug report here: https://code.google.com/p/gmaps-api-issues/issues/detail?id=5608#makechanges

    0 讨论(0)
  • 2021-02-16 00:36

    Since Arabic and Hebrew are causing problems, and English and Russian are not, I am going to guess that something is broken in the default info window implementation with respect to right-to-left (RTL) languages. Particularly if you are running your tests on Android 4.2, it may be that Maps V2's default info window contents have incorrectly applied the various RTL-related attributes.

    Fortunately, you can supply your own info window contents, by implementing InfoWindowAdapter and having getInfoContents() return the View that you want to use in the info window.

    For example, this sample project (from tomorrow's update to my book) shows customizing the info window using this InfoWindowAdapter:

    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);
      }
    }
    

    If you want to replace the whole window, you would have getInfoWindow() return a View. If getInfoWindow() returns null, getInfoContents() is used for the contents of the window. You then attach an instance of InfoWindowAdapter via setInfoWindowAdapter() on your GoogleMap.

    In your case, you could use your own layout to make sure that you are implementing RTL correctly. That should, in principle, clear up this problem. It is conceivable that Maps V2 does something strange that breaks RTL code that normally should work, in which case you'd need to file an issue.

    0 讨论(0)
提交回复
热议问题