Google Maps Android API v2,标记标题/片段显示错误

2024-03-16

我使用 Google Maps Android API v2 与 Android 来显示当前位置和附近的标记。 使用 Google Places API 接收附近地点的位置和标题。

问题是标题/片段中的非英文名称显示失败。 例如,希伯来语名字。

附上截图。

Screenshot)


由于阿拉伯语和希伯来语会引起问题,而英语和俄语则不会,因此我猜测默认信息窗口实现中关于从右到左 (RTL) 语言的某些内容出现了问题。特别是如果您在 Android 4.2 上运行测试,则可能是 Maps V2 的默认信息窗口内容错误地应用了各种 RTL 相关属性。

幸运的是,您可以通过实现来提供自己的信息窗口内容InfoWindowAdapter并拥有getInfoContents()返回View您想在信息窗口中使用的。

例如,这个示例项目 https://github.com/commonsguy/cw-omnibus/tree/master/MapsV2/Popups(从明天更新到我的书)显示使用此自定义信息窗口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);
  }
}

如果你想更换整个窗户,你会getInfoWindow()返回一个View. If getInfoWindow()回报null, getInfoContents()用于窗口的内容。然后您附加一个实例InfoWindowAdapter via setInfoWindowAdapter()在你的GoogleMap.

对于您的情况,您可以使用自己的布局来确保正确实现 RTL。原则上,这应该可以解决这个问题。可以想象,Maps V2 做了一些奇怪的事情,破坏了通常应该工作的 RTL 代码,在这种情况下,您需要提出问题 http://code.google.com/p/gmaps-api-issues/issues/list.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Google Maps Android API v2,标记标题/片段显示错误 的相关文章

随机推荐