gpt4 book ai didi

google-maps - Google 地方信息自动填充仅限澳大利亚的限制

转载 作者:行者123 更新时间:2023-12-04 17:19:33 31 4
gpt4 key购买 nike

如何将 Google 地方信息仅限于澳大利亚?

这是我正在使用的代码:

function initialize() {

var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);
}

google.maps.event.addDomListener(window, 'load', initialize);

最佳答案

来自 autocomplete documentation :

Restrict the search to a specific country

Use the componentRestrictions option to restrict the autocomplete search to a particular country. The following code restricts the results to cities within France.

var input = document.getElementById('searchTextField');
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'fr'}
};

autocomplete = new google.maps.places.Autocomplete(input, options);

对于澳大利亚,请使用“au”:

function initialize() {
var options = {
componentRestrictions: {country: 'au'}
};

var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input, options);
}

google.maps.event.addDomListener(window, 'load', initialize);

代码片段:

function initialize() {
var options = {
componentRestrictions: {country: 'au'}
};

var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input, options);
}

google.maps.event.addDomListener(window, 'load', initialize);
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<input id="searchTextField" type="text" />

关于google-maps - Google 地方信息自动填充仅限澳大利亚的限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30835358/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com