Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve English Results in Google Maps API V3

//....
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
directionsService = new google.maps.DirectionsService();
var request = {
    origin : new google.maps.LatLng(origin.lat, origin.lng),
    destination : new google.maps.LatLng(destination.lat, destination.lng),
    travelMode : google.maps.DirectionsTravelMode.DRIVING,
    unitSystem : google.maps.DirectionsUnitSystem.METRIC,
    region: 'de'
    };
directionsService.route(request, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(result);
    }
});
//....

As a result I get something like this

Head southwest on 吳江路/吴江路 toward 泰兴路/泰興路
Turn left at 茂名北路
Continue onto 茂名南路
Turn right at 淮海中路
Slight left to stay on 淮海中路
Turn left at 华山路/華山路

The instructions are English on my browser, and French on my French colleagues French Firefox, the street names are Chinese, I thought I requested information in German region: 'de'

Now ok, maybe the Chinese streets are not available in German, but setting region to gb, en, even zh seems to do nothing. I really would like the text just to be one language, preferably English.

edit I am quite sure the street names are available in English, because when I use the Geocoder results are in English e.g Shimen Road (No.1)

edit2 with http://maps.google.com/maps/api/js?sensor=false&language=cs I am able to force the instructions into a language, but still the street names are stuck in Chinese. Using the geocoder api i can receive chinese street names that are Chinese translated into English/German/French (with fallback to english when german/french translations are missing) so why the directions street names is stuck on Chinese does not make sense. It could be just a flaw/deliberate on google's side, but I kind of doubt it.

Is there a reason

like image 336
Moak Avatar asked Mar 18 '11 11:03

Moak


1 Answers

DirectionRequest doesn't have a parameter to specify language. The language is distinguished according to the language used for the map. The language is either specified as an optional language parameter in the <script> tag e.g.

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

or if the parameter is not present the browser's preferred language is used.

If you want to use different language for the direction results and the map, you can use Google Directions API:

http://code.google.com/apis/maps/documentation/directions/

The result is JSON text. To use it easily, it should be sufficient just to convert it to an object.

The region parameter (both in the maps' DirectionRequest and Directions API) doesn't change the language, it serves other purpose. It affects results to be biased towards some region (e.g. the default result for 'Toledo' is the city in Ohio USA, if you want the one in Spain, use region=es to bias the results).

like image 168
Tomik Avatar answered Oct 07 '22 01:10

Tomik