admin管理员组

文章数量:1410705

is it possible to restrict the autoplete search only to cities and postal code?

This won't work:

autoplete = new google.maps.places.Autoplete(
                    /** @type {!HTMLInputElement} */(document.getElementById('autoplete')),
                    {types: ['(cities', '(postal_code)'], ponentRestrictions: {country: "de"}});

Maybe this is right?

autoplete = new google.maps.places.Autoplete(
                    /** @type {!HTMLInputElement} */(document.getElementById('autoplete')),
                    {types: ['(regions)'], ponentRestrictions: {country: "de"}});

Source:

But autoplete also show some results outside my restricted country, why?

Some suggestions?

Solution

autoplete = new google.maps.places.Autoplete(
                    /** @type {!HTMLInputElement} */(document.getElementById('autoplete')),
                    {types: ['(regions)'], ponentRestrictions: {'country': "de"}});

is it possible to restrict the autoplete search only to cities and postal code?

This won't work:

autoplete = new google.maps.places.Autoplete(
                    /** @type {!HTMLInputElement} */(document.getElementById('autoplete')),
                    {types: ['(cities', '(postal_code)'], ponentRestrictions: {country: "de"}});

Maybe this is right?

autoplete = new google.maps.places.Autoplete(
                    /** @type {!HTMLInputElement} */(document.getElementById('autoplete')),
                    {types: ['(regions)'], ponentRestrictions: {country: "de"}});

Source: https://developers.google./places/supported_types

But autoplete also show some results outside my restricted country, why?

Some suggestions?

Solution

autoplete = new google.maps.places.Autoplete(
                    /** @type {!HTMLInputElement} */(document.getElementById('autoplete')),
                    {types: ['(regions)'], ponentRestrictions: {'country': "de"}});
Share edited Jul 25, 2018 at 8:44 yfain asked Jul 25, 2018 at 6:33 yfainyfain 4967 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

The code below is the correct answer to my question.

autoplete = new google.maps.places.Autoplete(
                    /** @type {!HTMLInputElement} */(document.getElementById('autoplete')),
                    {types: ['(regions)'], ponentRestrictions: {'country': "de"}});

本文标签: javascriptGoogle Maps Autocompleteonly cities and postal codeStack Overflow