<form>
<input id="pac-input" value="" class="controls" type="text" placeholder="Search Box">
<input type="button" id="find" value="find" />
</form>
<script>
function initAutocomplete() {
var options = {
componentRestrictions: { country: "IN" }
};
// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.Autocomplete(input, options);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9CiSrNomU7HPw5PLIpFZYP6NXXOq0dlE&libraries=places&callback=initAutocomplete"
async defer></script>
我希望在搜索框文本中使用&#34; Maharashtra,india&#34;,&#34; mumbai&#34;,&#34; india&#34;不应该来。基本上我只需要地区和地方,而不是州名或城市名称出现在建议中。 有人可以帮忙吗?
答案 0 :(得分:0)
请参阅: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete
如果您查看“JavaScript + HTML&#39;”中的示例代码。部分,API允许您设置过滤器,例如,企业。因此,只需根据您的标准设置类型,您应该好好去。
干杯, Mrugesh
答案 1 :(得分:0)
How to limit google autocomplete results to City and Country only
您可以参考此答案。
function initialize() {
var options = {
types: ['(regions)'],
componentRestrictions: {country: "us"}
};
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input, options);
}