How to change language Google Map V2 android

我与影子孤独终老i 提交于 2020-01-19 01:23:07

问题


I am using google-play-service-lib. How can I change language of google map i.e. show locations in korian language or Hindi Language.


回答1:


You can change location for Google Maps that use the Google Map API V2 by using a Locale Object. The language needs to be supported on the device being used though.

Here is the full list of supported languages.

With this code below I was able to change the language on the map to Chinese:

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

    String languageToLoad = "zh_CN";
    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);

    setUpMapIfNeeded();

}

Result, language set to Chinese in the code (no manual changes) on a U.S. based phone:

I was also able to get it to show Korean, use this Locale code:

 String languageToLoad = "ko_KR";

Result:

NOTE

It looks like the supported languages for Google Maps are listed here: https://developers.google.com/maps/faq#languagesupport




回答2:


We only need to change the location in the application to get the Map´s descriptions with different language. We have to add validations to avoid the use of deprecated methods:

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        String language= "hi"; //Hindi language!.
        Locale locale = new Locale(language);
        Locale.setDefault(locale);
        Configuration config = new Configuration();

        if(Build.VERSION.SDK_INT>Build.VERSION_CODES.JELLY_BEAN){
           config.setLocale(locale);
           getContext().createConfigurationContext(config);
        }else { //deprecated 
           config.locale = locale;
           getResources().updateConfiguration(config, getResources().getDisplayMetrics());
        }

...
...

...

Very important to say that all the languages are not supported, this is an example in Russian language:

We can get the code languages from:

https://www.transifex.com/explore/languages/




回答3:


Just change the locale on the device. If translations are available, they will be shown automatically.

A screenshot of my US phone with the locale switched to Korean:



来源:https://stackoverflow.com/questions/22863288/how-to-change-language-google-map-v2-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!