自动完成谷歌地图V3的地方不可能自定义



我将自动补全缩小到仅覆盖澳大利亚的区域和边界,但我仍然收到智利和中国以及所选区域之外的其他国家的自动补全。有人有解决这个问题的好办法吗?我也不能改变谷歌自动完成的样式,它是一个自我生成的Div与样式标签,克服了我的样式自动完成Div ?我开始使用Geocoder和Jquery自动完成过滤的结果,但它不工作以及谷歌自动完成的结果是少于谷歌地图自动完成?

我这样调用Library:

下面是创建自动完成的代码:
    var defaultBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(-47.5765257137462, 106.259765625),
    new google.maps.LatLng(-9.6, 179.359375));
    var options = {
      bounds: defaultBounds,
      types: ['geocode'],
      offset: 5
    };
    var input = document.getElementById('store-locator-header');
    var autocomplete = new google.maps.places.Autocomplete(input,options); 

现在,您可以使用以下命令限制一个国家:

componentRestrictions: {country: 'us'},

当使用bounds添加自动补全时,结果偏向,但不限制到包含在这些范围内的位置。这与在Geocoding API中使用Viewport bias时相同。恐怕我没有办法过滤掉那些不在bounds范围内的建议。

另一种快速自定义的方法是设置组件限制,如下所示

var autocomplete = new google.maps.places.Autocomplete(input);
//autocomplete.bindTo('bounds', map);//restrict to bounds or viewport
autocomplete.setComponentRestrictions({'country': 'uk'});//restrict to country

关于位置偏置的更多信息

问题是LatLngBounds期望西南和东北角

代替:

var defaultBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(-47.5765257137462, 106.259765625),
    new google.maps.LatLng(-9.6, 179.359375));

应该是:

var defaultBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(-9.6, 106.259765625),
    new google.maps.LatLng(-47.5765257137462, 179.359375));

实际上有文档来定义自动完成的UI元素的样式。

最新更新