2012-05-04 31 views
5

Tôi sử dụng bản đồ google api v3 để lấy tọa độ và địa chỉ từ một điểm, nhưng địa chỉ trả về của google bằng tiếng Pháp. Ở đây kịch bản tôi sử dụng để lấy địa chỉ, làm thế nào tôi có thể buộc bản đồ Google trả lại kết quả bằng tiếng Anh.Nhận địa chỉ từ bản đồ google api v3 bằng tiếng Anh

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

Trả lời

5

Theo documentation bạn có thể thay đổi ngôn ngữ của bài trình bày của API bản đồ bằng cách thêm một tham số language, như vậy:

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

Ngoài ra, theo this answer, bạn có thể thay đổi các dịch vụ sử dụng sử dụng lệnh google.load, như vậy:

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

(mã lấy từ câu hỏi được liên kết). Đây là liên kết đến số documentation cho google.load. Tôi đang suy nghĩ thay đổi base_domain sẽ đạt được kết quả mong muốn, nhưng tôi đã không thử nghiệm nó.

+0

cảm ơn bạn rất nhiều :) – Houx

+1

Vui vì tôi có thể giúp, Houx! –

Các vấn đề liên quan