Javascript 如何获取lat&;仅限邮政编码和国家/地区限制

Javascript 如何获取lat&;仅限邮政编码和国家/地区限制,javascript,google-maps,google-maps-api-3,maps,geocoding,Javascript,Google Maps,Google Maps Api 3,Maps,Geocoding,是否可以仅从邮政编码和国家/地区限制中正确返回lat lon 以下是我所拥有的: $scope.getLatLongFromPostcode = function(code) { var geocoder = new google.maps.Geocoder(); geocoder.geocode({ address: code + '', // force string hack componentRestrictions : { count

是否可以仅从邮政编码和国家/地区限制中正确返回lat lon

以下是我所拥有的:

$scope.getLatLongFromPostcode = function(code) {        
  var geocoder = new google.maps.Geocoder();
  geocoder.geocode({
    address: code + '', // force string hack
    componentRestrictions : {
      country : 'AU'
    }
  }, function postcodesearch(results, status) {
    var searchCode = null;            
    if (status == google.maps.GeocoderStatus.OK) {
      var location = [results[0].geometry.location.lat(), results[0].geometry.location.lng()]
      console.log('location', location[0],location[1]
    }
  });
}
虽然这似乎适用于某些邮政编码,但并非所有邮政编码都适用,例如:

2263返回-33.2504355151.5077645,它正确地指向正确的郊区


但是,如果我搜索6937,它会返回-25.274398 133.7751359999997,这是澳大利亚的死中心,这是不正确的,因为它应该在Tuart Hill的珀斯附近。

除了指定国家和邮政编码外,您还可以提供
地区
来进行组件筛选吗?看,我猜一个四位数的代码不足以唯一地识别像澳大利亚这样大的国家的地址。我尝试过使用这个精确的资源,但是6937仍然没有返回结果。你指定了什么地方?我只有邮政编码,因为我的问题表明我只能按邮政编码搜索,所以我使用了“postalCode”:组件限制中的代码,但它仍然不起作用。谷歌的地理编码数据库似乎缺少6937,正在返回澳大利亚的地理编码结果。