javascript - Limit google autocomplete to a postal code - Stack Overflow

Trying to work with the Google Autoplete without maps, but it's being troublesome.<script>va

Trying to work with the Google Autoplete without maps, but it's being troublesome.

<script>
  var autoplete;
  var countryRestrict = {country: 'NO', postalCode: '0365'}
  function initAutoplete() {
    autoplete = new google.maps.places.Autoplete(
      (document.getElementById('address-field')),
      { types: ['address'],
        ponentRestrictions: countryRestrict
      });
  }
</script>
<script src=";libraries=places&callback=initAutoplete"
        async defer></script>

when I add postalCodeto countryRestrict it stops working, yet I see in their own example that they seem to be restricting it by using the example:

ponentRestrictions: {country: "AU", postalCode: "2000"}

Is it possible for me to limit the address autoplete to a given postal code?

Trying to work with the Google Autoplete without maps, but it's being troublesome.

<script>
  var autoplete;
  var countryRestrict = {country: 'NO', postalCode: '0365'}
  function initAutoplete() {
    autoplete = new google.maps.places.Autoplete(
      (document.getElementById('address-field')),
      { types: ['address'],
        ponentRestrictions: countryRestrict
      });
  }
</script>
<script src="https://maps.googleapis./maps/api/js?key=API-KEY&libraries=places&callback=initAutoplete"
        async defer></script>

when I add postalCodeto countryRestrict it stops working, yet I see in their own example that they seem to be restricting it by using the example:

ponentRestrictions: {country: "AU", postalCode: "2000"}

https://developers.google./maps/documentation/javascript/examples/geocoding-ponent-restriction

Is it possible for me to limit the address autoplete to a given postal code?

Share Improve this question edited Mar 7, 2016 at 15:02 geocodezip 161k14 gold badges227 silver badges255 bronze badges asked Mar 7, 2016 at 10:55 Sebastian Jennings AlmnesSebastian Jennings Almnes 1,6082 gold badges20 silver badges33 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Currently it's not possible, the only supported ponentRestriction for an Autoplete is country (The linked example is an implementation of geocoding, where more ponentRestrictions are supported )

Adding other ponentRestrictions than the supported options results in a script-error which breaks the Autoplete

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745260458a4619188.html

相关推荐

  • javascript - Limit google autocomplete to a postal code - Stack Overflow

    Trying to work with the Google Autoplete without maps, but it's being troublesome.<script>va

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信