Google Maps API Tutorial

© 2007, 2008, 2009 Mike Williams

 
Translate this page:

 

Using different languages

Normally, the text used by the API will be in US English.

The API will look through the preferred languages in your browser options and use the first language that Google supports.

If you wish to specify a particular language, then you can add a "hl" parameter to the line that loads the API code, e.g.
src="http://maps.google.com/maps?file=api&v=2&hl=de&key=abcdefg"
The official list of supported languages is kept here: code.google.com/support/bin/answer.py?answer=60737&topic=12267

A slightly different, but equally official, list is available on this spreadsheet, in the "localized" column. gmaps-samples.googlecode.com/svn/trunk/mapcoverage_filtered.html

Directions details

When you use GDirections, by default, the route description text will be in the same language as that used in the API as described above.

If you want to use a different one of the supported languages, then you can add the locale option to your .load() or .loadFromWaypoints() call, e.g. gdir.load("from: Detroit to: Dayton", {locale:"fr"});.

Other languages

If you want to use a language that's not yet supported by Google then you can do it like this example. All I've done there is replace the Google text with the same text in upper case. To use a real language, you'd need to translate all that text into your chosen language.

The way it works is that the API loader uses GAddMessages() to pass the language specific text strings to the main API code. We can overwrite those text strings with our own GAddMessages() call.

However, the GMapTypes are created before the loader returns control to our code. We can perform GAddMessages{10050: 'SATELLITE'} in our own code, but it's too late to affect the map type. What we can do, however, is create our own map types which are clones of the Google map types except that they use different texts in the "name" parameter and in the "shortName", "errorMessage" and "alt" options.

Copyright texts associated with a map type are generated in a server, so they're not accessible by that method. What we can do is write our own custommap.getCopyrights() method which reads through the prefixes and replaces any occurrences of "Map Data" and "Imagery" with the equivalent in the desired language.

There's no reasonable way to produce GDirections details in unsupported languages, because that's performed in the direction server.

Back to Mike's Homepage
Up to the start of this tutorial