jquery – 将自动填充列表中的国家/地区的Google地图限制为“INDIA,USA和UK”

代码无效.请告诉我确切的解决方
<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>

UPDATE

2017年1月,Maps JavaScript API版本3.27中引入了多个国家/地区过滤自动完成功能

You can Now restrict Autocomplete predictions to only surface from multiple countries. You can do this by specifying up to 5 countries in the componentRestrictions field of the AutocompleteOptions.

https://developers.google.com/maps/documentation/javascript/releases#327

解决方法

首先,您无法从多个国家/地区进行过滤.这是一个已知问题 reported here.

然后,对于您的代码,您必须使用两个字符的字符串作为国家/地区代码

componentRestrictions can be used to restrict results to specific
groups. Currently,you can use componentRestrictions to filter by
country. The country must be passed as as a two character,ISO 3166-1
Alpha-2 compatible country code. 07001.

这是一个国家working sample我jsfiddled(取自Google samples list).

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...