Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get address from google map api v3 in English

I use google map api v3 to get coordinate and address from a point, but google return address in French. Here the script i use to get the address, how can I force Google map to return the result in English.

 var map;
    var geocoder;
          var mapOptions = { center: new google.maps.LatLng(0.0, 0.0), zoom: 2,
            mapTypeId: google.maps.MapTypeId.ROADMAP };

  function initialize() {
        var myOptions = {
            center: new google.maps.LatLng(36.835769, 10.247693 ),
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

    geocoder = new google.maps.Geocoder();
    var map = new google.maps.Map(document.getElementById("map_canvas"),
    myOptions);
    google.maps.event.addListener(map, 'click', function(event) {
        placeMarker(event.latLng);
    });

    var marker;
    function placeMarker(location) {
        if(marker){ //on vérifie si le marqueur existe
            marker.setPosition(location); //on change sa position
        }else{
            marker = new google.maps.Marker({ //on créé le marqueur
                position: location, 
                map: map
            });
        }
        document.getElementById('lat').value=location.lat();
        document.getElementById('lng').value=location.lng();
        getAddress(location);
    }

  function getAddress(latLng) {
    geocoder.geocode( {'latLng': latLng},
      function(results, status) {
        if(status == google.maps.GeocoderStatus.OK) {
          if(results[0]) {
            document.getElementById("address").value = results[0].formatted_address;
          }
          else {
            document.getElementById("address").value = "No results";
          }
        }
        else {
          document.getElementById("address").value = status;
        }
      });
    }
  }
like image 624
Houx Avatar asked May 04 '12 01:05

Houx


1 Answers

According to the documentation you can change the language of presentation of the maps API by adding a language parameter, like so:

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

Alternatively, according to this answer, you can change the service used using the google.load command, like so:

<script type="text/javascript">
 google.load("maps", "2",{language: "de",base_domain: 'google.de'});
 ...
</script>

(code taken from linked question). Here's a link to the documentation for google.load. I'm thinking changing the base_domain will achieve the desired result, but I haven't tested it.

like image 140
Cianan Sims Avatar answered Oct 23 '22 12:10

Cianan Sims