【问题标题】:Autocomplete Google Map V3 Places impossible to customize?自动完成 Google Map V3 无法自定义的地方?
【发布时间】:2011-11-25 15:32:22
【问题描述】:

我将自动完成功能缩小到一个区域和仅涵盖澳大利亚的范围,但我仍在接收与智利和中国以及所选区域之外的其他国家/地区的自动完成功能。 有没有人有一个很好的解决方案来解决这个问题? 我也无法更改 Google 自动完成的样式,它是一个带有样式标签的自行生成的 Div,它克服了我的自动完成 DIV 的样式? 我开始使用 Geocoder 和 Jquery 自动完成来过滤结果,但效果不如 Google 自动完成,结果不如 google 地图自动完成?

我这样称呼图书馆:

这是创建自动完成的代码:

    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); 

【问题讨论】:

    标签: google-maps autocomplete google-geocoder


    【解决方案1】:

    问题在于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));
    

    其实有documentation to style the UI elements of Autocomplete

    【讨论】:

      【解决方案2】:

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

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

      更多关于地点偏向here

      【讨论】:

        【解决方案3】:

        现在,您可以限制在一个国家/地区:

        componentRestrictions: {country: 'us'},

        【讨论】:

          【解决方案4】:

          Adding Autocompletebounds 时,结果偏向,但不限于包含在这些范围内的地点。 这与在Geocoding API 中使用Viewport Biasing 时相同。恐怕我没有办法过滤掉那些不属于bounds 的建议。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-08-09
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-07-26
            相关资源
            最近更新 更多