Maps SDK for Web

Class LocaleService

Service for store and retrieve an specific locale setting.

This service is used by map instances, widgets and services to store their locale configuration.

If its constructor receive a LocaleService instance as argument it will start listen changes in the given instance and apply the same change in its own. That behavior allows the instances of this class to be updated in cascade.

Constructor

LocaleService([parent])

Parameters
Name Description Required Type/Values Default
parent If is defined makes the new instance a "slave" of the given instance No LocaleService None
Example
// Will use the global LocaleService
// You can obtain the global LocaleService calling tomtom.globalLocaleService()
tomtom.nearbySearch()
  .go()

// Will ignore the global LocaleService and use the provided language
tomtom.nearbySearch()
  .language('pl-PL')
  .go();

// Example how to use locales which are set per map instance
var mapLanguage = mapInstance.getLocaleService().getCurrentLocale();
tomtom.nearbySearch()
  .language(mapLanguage)
  .go();

Methods

getCurrentLocale( ): Locale

Returns the current locale.

Returns

LocaleService.getLocalesFor([serviceType=null]): Locale[] Static

Static method that returns an array with the supported locales which are supported by given service type.

Parameters
Name Description Required Type/Values Default
serviceType No "traffic" | "routing" | "search" | "maps" | "reverseGeocoder" null
Returns

setCurrentLocale([locale="en-GB"])

Sets locale used by a service instance.

Fires the event LOCALE_CHANGED.

Parameters
Name Description Required Type/Values Default
locale String (with language code) or Locale instance No String | Locale "en-GB"

Events

All the class events are keys of the Events static member.

To learn more about how to listen events please refer to this documentation.

LOCALE_CHANGED : String

Fired after the locale was changed.
Example
var localeService = new LocaleService();
localeService.on(L.LocaleService.Events.LOCALE_CHANGED, function(eventData) {
 console.log(eventData);
});