问题
I wont to limit the search limit to just one city (e.g "New York") and I need help with componentRestrictions options. Thanks!
<script type="text/javascript">
function initialize() {
var options = {
types: ['address'],
componentRestrictions: {country: "us", locality: "new york"}
};
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
回答1:
You can restrict it by adding NY_ Before your input example if you want to search Port Washington then your input will be NY_port_washington
Example Link
来源:https://stackoverflow.com/questions/49015517/google-places-api-how-to-limit-the-search-limit-to-just-one-city