【问题标题】:Reverse Geocode on Client Side (Google Maps V3 API)客户端反向地理编码(Google Maps V3 API)
【发布时间】:2011-09-27 08:52:59
【问题描述】:

如何使用 Google Maps V3 API 在客户端执行反向地理编码?从地址到 LatLng 的正向地理编码是直接的(代码如下),但是如何对反向地理编码执行相同的操作?

普通地理编码:

geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
    map: map,
    position: results[0].geometry.location
  });

【问题讨论】:

    标签: javascript google-maps geocoding reverse-geocoding


    【解决方案1】:

    过程完全相同,只是提供了一个 LatLng 对象,而不是向地理编码函数提供地址对象

    反向地理编码:

    var input = document.getElementById("latlng").value;
    var latlngStr = input.split(",",2);
    var lat = parseFloat(latlngStr[0]);
    var lng = parseFloat(latlngStr[1]);
    var latlng = new google.maps.LatLng(lat, lng);
    
    geocoder.geocode({'latLng': latlng}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        if (results[1]) {
          map.setZoom(11);
          marker = new google.maps.Marker({
              position: latlng, 
              map: map
          }); 
          infowindow.setContent(results[1].formatted_address);
          infowindow.open(map, marker);
        } else {
          alert("No results found");
        }
      } else {
        alert("Geocoder failed due to: " + status);
      }
    });
    

    Example directly from Google

    希望对您有所帮助。

    【讨论】:

    • 您知道反向地理编码请求是否会影响每天 2500 次的正常地理编码限制?
    • 我几乎可以肯定它确实如此。这是相同的方法调用,只是参数不同。只要确保您正在从客户端进行地理编码,您应该就可以了。
    • 很抱歉这么晚才发表评论,但我很确定如果地理编码是在客户端完成的,那么配额不是每天 2500 个请求。在这里查看:developers.google.com/maps/articles/geocodestrat#client
    猜你喜欢
    • 2012-06-08
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 2013-12-18
    • 2011-07-17
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    相关资源
    最近更新 更多