google-maps - 如何在 Google Map V2 android 中将语言更改为波斯语

标签 google-maps android-maps-v2

我需要以波斯语显示 map 。

我尝试了这段代码,但 map 仍然以英文加载

Locale locale = new Locale("fa");    
Locale.setDefault(locale);    
android.content.res.Configuration config = new android.content.res.Configuration();   
config.locale = locale;   
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    config.setLayoutDirection(config.locale);
}    
DisplayMetrics dm = context.getResources().getDisplayMetrics();
context.getResources().updateConfiguration(config, dm);

最佳答案

您可以使用 Locale对象更改 Google Maps API V2 的位置。不过,所使用的设备需要支持该语言。

要将英语更改为波斯语,请使用以下区域设置代码:

//[Persian]
 String languageToLoad = "fa_";  

检查这个link对于其他支持的语言。

示例代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String languageToLoad = "fa_";
    Locale locale = new Locale(languageToLoad);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());

    setContentView(R.layout.activity_maps);

}

希望这有帮助! :)

更新:

用另一种语言(例如阿拉伯语)尝试了上面的代码 - String languageToLoad = "ar_EG"; 效果很好。见下图。

enter image description here

您可以查看这个google example并选择要在 map 中加载的语言。根据您的情况,选择波斯语语言。我认为谷歌仍然以英语加载 map 中的文本。波斯语只会在其他函数中加载,如下例所示:

英文:
enter image description here

波斯语:
enter image description here

希望这有帮助! :)

关于google-maps - 如何在 Google Map V2 android 中将语言更改为波斯语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37392870/

相关文章:

Android Maps API 2 SHA-1 key 用法

java - map 应用程序在打开时崩溃

google-maps - 如何在通过鼠标拖动选择的区域内获取标记?

android - 谷歌地图 v2 android api key 仅适用于调试 key

android - 尝试在 FrameLayout 中使用 MapFragment 时出现错误/异常

java - marker.isVisible 为 true,但没有显示任何标记

jquery - 为什么在使用 jQuery Mobile 时 Google map 控件和 InfoWindow 损坏/倾斜?

javascript - 使用 JSON 数据用数据库对象填充 Google map

java - Android,尝试使用折线在 map 上绘制/记录自行车骑行

android - 从android中的地址获取经纬度