2012-05-04 8 views
5

Googleマップapi v3を使用して座標と住所を取得しますが、Googleの住所はフランス語で取得します。ここで私はアドレスを取得するためにスクリプトを使用して、どのように私は英語で結果を返すようにGoogleマップを強制することができます。google map api v3のアドレスを英語で取得

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

答えて

5

documentationあなたがそうのように、languageパラメータを追加することにより、マップのAPIのプレゼンテーションの言語を変更することができますによると:

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

また、this answerによると、あなたが使用するサービスを変更することができます次のようにgoogle.loadコマンドを使用してください。

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

(リンクされた質問から取得したコード) google.loadの​​へのリンクは次のとおりです。私はbase_domainを変更することが望ましい結果を達成すると思っていますが、私はそれをテストしていません。

+0

ありがとうございました:) – Houx

+1

うわー、私は助けてくれるでしょう、ホウ! –

関連する問題