Google Maps Internationalization

English: Wordmark of Google Maps

Google Maps API supports internationalization of user interface and locations names. In order to add language definition to our map we have to provide additional parameter language to <script> declaration.

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&language=sl"></script>

Source:
https://developers.google.com/maps/documentation/javascript/basics

With this kind of language declaration we can define only one language (if we forget JavaScript DOM manipulation). What we need is dynamically loaded Google Maps API and Google Loader is the right choice for this kind of job. It is capable of loading several JavaScript libraries like Google Maps API, Google Data APIsGoogle Visualization API… For more information click here. Google Loader API requires <script> declaration in header of HTML  document:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

And this is an example of dinamicly loaded Goolge Maps API with provided language and callback function which builds a new map:

<script type="text/javascript" src="https://www.google.com/jsapi">  function mapsLoaded() { ... }
   google.load("maps", "3", {"callback" : mapsLoaded, "language": "sl", "other_params": "sensor=false"});
</script>

And what is wrong whit this code?

The language is never set properly. What actually works is language declaration inside other_params like this:

<script type="text/javascript" src="https://www.google.com/jsapi">  function mapsLoaded() { ... }
   google.load("maps", "3", {"callback" : mapsLoaded, "other_params": "sensor=false&language=sl"});
</script>

Do not forget sensor parameter!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s