RIADUL ISLAM
RIADUL ISLAM

Reputation: 21

How to show google maps area name with both english and local language in android google map sdk

I want to show locations name both in English and local language like Maps app show in android.

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));
    }
}

But when i run this code all locations name in map is in English. But i want to the output like this

here where the location name is both in English and Bengali.

Upvotes: 1

Views: 1229

Answers (2)

Shawn Domingo
Shawn Domingo

Reputation: 1401

With regards to localizing the Google Map SDK, there is no definite way to do this, there are currently no class or reference that can be called in order to change the language of the Google Maps SDK, the localization of the Map is only available at the moment for Maps Javascript API, What you can do as a workaround is to change the language of your device in the Settings of the Android device as this will influence the results in the map. However, this doesn't always work for every place. Hope this helps.

If you'd like to have a feature that can explicitly influence the Android Maps SDK, I would suggest that you file a Feature Request at the Google Issue Tracker in order for their engineers to review the feasibility of your request.

Upvotes: 0

Marat Zangiev
Marat Zangiev

Reputation: 1382

You need to add new configuration with Locale that you need. Check out this

Upvotes: 1

Related Questions