Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 problem is that non-english names at title/snippet are shown in fail way. For the instance, Hebrew names.

The sreenshot is attached.

Screenshot)

like image 886
Oleg Karakoz Avatar asked Jan 02 '13 12:01

Oleg Karakoz


People also ask

How do I change the marker on Google Maps API?

Call the changeMarkerPosition() function and pass the marker object in it. The setPosition() will change the marker position on google map based on the specified latitude and longitude.

How do I start a custom image on Google Maps marker for mobile app?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements.


2 Answers

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.

like image 96
CommonsWare Avatar answered Oct 24 '22 23:10

CommonsWare


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

like image 34
elcuco Avatar answered Oct 24 '22 23:10

elcuco