【问题标题】:Google Maps Geocoder: Return postal_code谷歌地图地理编码器:返回 postal_code
【发布时间】:2011-12-05 02:48:25
【问题描述】:

我正在使用jQuery UI来使用Google Maps Geocoder,以及选择地址时,返回地理码信息。这是sn-p:

$('#address-dropdown').autocomplete({
  //Use geocoder to fetch lat+long values from an address input using google maps API
  source: function(request, response) {
    geocoder.geocode( {'address': request.term }, function(results, status) {
      response($.map(results, function(item) {
        return {
          label: item.formatted_address,
          value: item.formatted_address,
          location: item.geometry.location,
          latitude: item.geometry.location.lat(),
          longitude: item.geometry.location.lng()
        }
      }));
    })
  },

我需要能够返回使用“邮政编码”以检查他们是否居住在允许的区域内。这是一个示例输出:http://maps.googleapis.com/maps/api/geocode/json?address=1601+Main+St+Eaton+Rapids+MI+48864&sensor=false

如何定位 postal_code 信息?

【问题讨论】:

    标签: jquery google-maps-api-3 geocoding google-geocoder


    【解决方案1】:

    看我的例子:http://jsfiddle.net/nEKMK/

    o 是你的对象。

    if (o.results[0].address_components) {
        for (var i in o.results[0].address_components) {
            if (typeof(o.results[0].address_components[i]) === "object" && o.results[0].address_components[i].types[0] == "postal_code") {
                var result = o.results[0].address_components[i].long_name;
            }
        }
    }
    if (!result) {
        alert("Error, there is no postal code");
    } else {
       alert(result);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多