如何在安卓谷歌地图SDK中显示英语和本地语言的谷歌地图区域名称



我想用英语和当地语言显示位置名称,例如地图应用程序在安卓中显示。

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
    private final static String TAG = MapsActivity.class.getSimpleName();
    private GoogleMap mMap;
    private SupportMapFragment mapFragment;
    private String language = "bn";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        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());
        }
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        LatLng dhaka = new LatLng(23.8103, 90.4125);
        mMap.addMarker(new MarkerOptions().position(dhaka));
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(dhaka,10f));
    }
}

但是当我运行此代码时,地图中的所有位置名称都是英文的。但是我想像这样输出

这里的地点名称是英语和孟加拉语。

您需要使用

所需的Locale添加新配置。看看这个

关于本地化Google Map SDK,没有明确的方法来做到这一点,目前没有可以调用的类或引用来更改Google Maps SDK的语言,地图的本地化目前仅适用于Maps Javascript API,您可以做的解决方法是在Android的Settings中更改设备的语言设备,因为这会影响地图中的结果。但是,这并不总是适用于每个地方。希望这有帮助。

如果你想要一个可以明确影响Android Maps SDK的功能,我建议你在谷歌问题跟踪器上提交一个功能请求,以便他们的工程师审查你的请求的可行性。

最新更新