【发布时间】:2012-07-02 16:40:58
【问题描述】:
此代码不起作用。请告诉我确切的解决方案
<script src="maps.googleapis.com/maps/api/…; type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var input = document.getElementById('searchTextField');
/* restrict to multiple cities? */
var options = {
types: ['(cities)'],
componentRestrictions: {country: ["usa", "uk"]}
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
更新
2017 年 1 月,Maps JavaScript API 3.27 版中引入了多个国家/地区过滤器自动完成功能:
您现在可以将自动完成预测限制为仅来自多个国家/地区的显示。您可以通过在 AutocompleteOptions 的 componentRestrictions 字段中指定最多 5 个国家/地区来做到这一点。
https://developers.google.com/maps/documentation/javascript/releases#327
【问题讨论】:
-
它必须是精确的解决方案!
-
@elclanrs Lmao :P, OP - man whats the relationship between autocomplete and google-map 详细说明你的问题 lil more bru!
-
您的脚本标签中忘记了双引号
-
我想展示,1。如果用户在文本框中输入“美国”(文本框应该是自动完成)然后谷歌地图显示“美国”地图 2.如果用户输入“英国”然后谷歌地图显示“英国”地图在自动完成文本框中国家应该是美国和英国跨度>
-
您的意思是在输入地址时希望地图将您带到您输入的地方?
标签: jquery google-maps