【问题标题】:Get address from google map api v3 in English从 google map api v3 获取英文地址
【发布时间】:2012-05-04 01:26:01
【问题描述】:

我使用 google map api v3 从某个点获取坐标和地址,但 google 以法语返回地址。这里是我用来获取地址的脚本,如何强制谷歌地图返回英文结果。

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

【问题讨论】:

    标签: google-maps localization


    【解决方案1】:

    根据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 的 documentation 的链接。我在想改变 base_domain 会达到预期的效果,但我还没有测试过。

    【讨论】:

      猜你喜欢
      • 2012-05-04
      • 2013-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多