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.
Here is how to change Google Maps navigation language: Open the Google Maps app, on your Android phone or tablet, Now tap on your profile picture or initial Account Circle and then Settings. Then tap on Navigation settings and then on Voice. Choose a voice and language.
About. Angular Google Maps is a set of directives (part of angular-ui) written in CoffeeScript and Javascript which integrate Google Maps in an AngularJS applications.
With style options you can customize the presentation of the standard Google map styles, changing the visual display of features like roads, parks, businesses, and other points of interest.
In order to change map's language, a bunch of localized JS scripts need to be refetched anew. So, you can just try to refresh entire page (JS not Angular) providing wanted language via local storage for example:
@NgModule({
imports: [
AgmCoreModule.forRoot({
apiKey: 'MY_KEY',
language: localStorage && localStorage.gml || 'en'
}),
]
})
to reload your page, use window.location.reload()
method
StackBLITZ: https://stackblitz.com/edit/angular-google-maps-demo-f3xzhn?file=app%2Fapp.module.ts
In app.component add the following make sure upon language change to update "lang" in local storage and reload the page using window.location.reload()
export class AppComponent implements OnInit {
constructor() { }
ngOnInit() {
var script = document.createElement('script');
script.src = `https://maps.googleapis.com/maps/api/js?v=quarterly&key=${KEY}&libraries=places&language=${localStorage && localStorage.lang || 'en'}`;
document.head.appendChild(script);
}
}
In your relevant module add:
@NgModule({
imports: [
AgmCoreModule.forRoot(),
]
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With