Wednesday, June 19, 2013

How can I change the language of Google Maps on the run?

A language can be selected when you load the API by appending language=XX to the API URL whereXX is the two-character language code (en for English, ar for Arabic, etc.) to the URL in the API call. See http://code.google.com/apis/maps/documentation/javascript/basics.html#Localization for documentation.
This won't let you change it on the fly, and I don't think you can do that. You can try loading the API a second time after getting the initial info you need in one language. But that seems likely to cause problems.
A cleaner way to do it might be to create a separate page that acts as a sort of web service for you. It accepts two parameters: A language code and an address. It loads the API using the language code requested, and reverse geocodes the address, providing the result. Your page would call this web service-like thing twice, once for each language, and then use the results as desired.

No comments: