2012-05-04 13 views
5

Io uso google map api v3 per ottenere coordinate e indirizzi da un punto, ma indirizzo di ritorno di Google in francese. Qui lo script che uso per ottenere l'indirizzo, come posso forzare Google map a restituire il risultato in inglese.Ottieni indirizzo da google map api v3 in inglese

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; 
     } 
     }); 
    } 
    } 

risposta

5

Secondo il documentation è possibile cambiare la lingua di presentazione della API di Google Maps con l'aggiunta di un parametro language, in questo modo:

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

In alternativa, secondo this answer, è possibile modificare il servizio utilizzato utilizzando il comando google.load, in questo modo:

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

(codice preso dal problema legato). Ecco un collegamento allo documentation per google.load. Sto pensando di cambiare base_domain raggiungerà il risultato desiderato, ma non l'ho testato.

+0

grazie mille :) – Houx

+1

Contento di aver potuto aiutare, Houx! –

Problemi correlati