question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change Map language dynamically

See original GitHub issue

Is it possible to change map language dynamically when language is changed ? Or at least have the language map changed the next time I access it (after language is changed).

I can set default language on map loading using this code (in mymap.module.ts) :

@NgModule({ imports: [ AgmCoreModule.forRoot({ apiKey: 'MY_KEY', language: 'es', }), ], })

And I can get the current language using this.translate.currentLang (in mymap.component.ts).

But I don’t know how I can combine both.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
sebholsteincommented, May 23, 2018

this was already discussed in another issue. As the google maps api does not support this officially, AGM will not implement this

1reaction
mklimkin0190commented, Apr 24, 2018

Obviously, this approach will not work if you run your app with --aot flag. This actually makes sense. I was able to make it work with solution found here and window.localion.reload(). Even though the original question and answer are about overriding the API key and loading it separately, one can override any config field, including the language. Here’s the code of the load method in the custom MapsAPILoader:

    load(): Promise<void> {
        if (this._scriptLoadingPromise) {
            return this._scriptLoadingPromise;
        }
        const script = this._documentRef.getNativeDocument().createElement('script');
        script.type = 'text/javascript';
        script.async = true;
        script.defer = true;
        const callbackName = `angular2GoogleMapsLazyMapsAPILoader`;
        this._config.language = window.localStorage.language;
        script.src = this._getScriptSrc(callbackName);
        this._documentRef.getNativeDocument().body.appendChild(script);
        this._scriptLoadingPromise = new Promise<void>((resolve: Function, reject: Function) => {
            (<any>this._windowRef.getNativeWindow())[callbackName] = () => { console.log('loaded'); resolve(); };
            script.onerror = (error: Event) => { reject(error); };
        });
        return this._scriptLoadingPromise;
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Change angular-google-maps language dynamically
To do this, I've created a class called AppInitService. Here, I'll initialise various properties in my app on the fly, such as translation ......
Read more >
Change Map language dynamically · Issue #1358 - GitHub
Is it possible to change map language dynamically when language is changed ? Or at least have the language map changed the next...
Read more >
Changing the Map Language | Google Maps plugin for Craft ...
It's easy to change the language of your map by adding a few extra query parameters to the Google Maps API URL.
Read more >
Localizing the Map | Maps JavaScript API | Google Developers
You can customize your map for a specific country or region in the following ways: Change the default language settings. Specify a region...
Read more >
Change a map's language | Mapbox GL JS
Change a map's language ... Ready to get started? Create a free account to start building with Mapbox. ... Use setLayoutProperty to switch...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found