I am using this function to get all the instruction to go from a starting point to another point with the google Directions Service:
function calcRoute(mode,_originlat,_originlong,_destinationlat,_destinationlong,_waypoints,_sensor,_language) {
var start = _originlat+','+_originlong;
var end = _destinationlat+','+_destinationlong;
var request = {
origin: start,
destination: end,
waypoints: waypts,
region:"us",//Region to change language
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
//directionsDisplay.setDirections(response);
var route = response.routes[0];
var summaryPanel = document.getElementById("directions_panel");
summaryPanel.innerHTML = "";
// For each route, display summary information.
for (var i = 0; i < route.legs.length; i++) {
var routeSegment = i+1;
summaryPanel.innerHTML += "<b>Leg: " + routeSegment + "</b> ";
summaryPanel.innerHTML +=" "+ route.legs[i].start_address + " to ";
summaryPanel.innerHTML += route.legs[i].end_address + "<br />";
summaryPanel.innerHTML += route.legs[i].distance.text + "<br /><br />";
for (var j = 0; j < route.legs[i].steps.length; j++) {
var step=j+1;
summaryPanel.innerHTML += "step"+step+":"+route.legs[i].steps[j].instructions + "<br />";
}
}
}
});}
But the tag region doesn't take effect on the result:
Leg: 1 255 Rue Nepean, Ottawa, ON K2P 2N2, Canada to Ontario 637, Killarney, ON P0M, Canada
558 km
step1:Prendre la direction nord-est sur Nepean St vers Bank St/Ottawa Road 31
step2:Prendre la 1re à droite et rester sur Bank St/Ottawa Road 31
step3:Prendre à droite sur Catherine St/Ottawa Road 60
step4:Tourner à gauche pour rejoindre ON-417 W
step5:Continuer sur Trans-Canada Hwy/ON-17 W
step6:Au rond-point, prendre la 3e sortie sur McConnell St/Trans-Canada Hwy/ON-17 E
Continuer de suivre Trans-Canada Hwy/ON-17 E
step7:Rester sur la file de droite et suivre ON-17 N/ON-11 N/Twin Lakes Road pour rejoindre Trans-Canada Hwy/ON-11 N/ON-17 W
Continuer de suivre Trans-Canada Hwy/ON-17 W
step8:Prendre à gauche sur ON-64 N (panneaux vers Lavigne/Noël Ville)
step9:Tourner à gauche pour rester sur ON-64 N
step10:Prendre à droite sur Trans-Canada Hwy/ON-69 N
step11:Prendre à gauche sur ON-637 W (panneaux vers Killarney)
Leg: 2 Ontario 637, Killarney, ON P0M, Canada to 2241-2295 Madison Ave, Grand Sudbury, ON P3A 2R2, Canada
110 km
step1:Prendre la direction est sur ON-637 E
step2:Prendre à gauche sur Trans-Canada Hwy/ON-69 N
step3:À gauche, rejoindre SW Bypass/Trans-Canada Hwy/ON-17 E en direction de North Bay
step4:Prendre à gauche sur Kingsway/Regional Road 55 (panneaux vers Sudbury)
step5:Prendre à droite sur Falconbridge Rd/Regional Road 86
step6:Prendre à gauche sur Old Falconbridge Rd
step7:Prendre à gauche sur Madison Ave
Votre destination se trouvera sur la gauche
the result is always in french.
region option doesn't set the language.
As it's explained in Maps Concepts: Localization:
The Google Maps API uses the browser's preferred language setting when displaying textual information such as the names for controls, copyright notices, driving directions and labels on maps. In most cases, this is preferable; you usually do not wish to override the user's preferred language setting. However, if you wish to change the Maps API to ignore the browser's language setting and force it to display information in a particular language, you can add an optional language parameter to the tag when including the Maps API JavaScript code, specifying the language to use.
For example, if you want to have all information in Franch, you have to set:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&language=fr"></script>
The only other option is to change browser's preferred language setting as it is described in Setting language preferences in a browser. To make changes visible you have to reload the page after change is done.
Similar example in French preferred language setting:
step1:Prendre la direction sud sur Rue des Bleuets vers Allée des Épines
step2:Tourner à droite pour rester sur Rue des Bleuets
step3:Continuer sur Rue des Blés d'Or
step4:Prendre à gauche sur Rue du Champ d'Avoine
Votre destination se trouvera sur la gauche
and English preferred language setting:
step1:Head south on Rue des Bleuets toward Allée des Épines
step2:Turn right to stay on Rue des Bleuets
step3:Continue onto Rue des Blés d'Or
step4:Turn left onto Rue du Champ d'Avoine
Destination will be on the left
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With