【问题标题】:Google Places API - getQueryPredictions Restrict by Country/City/State?Google Places API - getQueryPredictions Restrict by Country/City/State?
【发布时间】:2012-11-17 04:52:59
【问题描述】:

下面是google给出的getQueryPredictions例子

service.getQueryPredictions({input: 'pizza near'}, callback);

有没有办法限制特定国家/城市/州的结果?

其他功能/组件有能力做到这一点

var input = document.getElementById('searchTextField');
var options = {  types: ['(cities)'],  componentRestrictions: {country: 'fr'}};
autocomplete = new google.maps.places.Autocomplete(input, options);

【问题讨论】:

    标签: google-maps google-places-api


    【解决方案1】:

    使用这个类似的函数(它比 getQueryPredictions 更强大一点):

    getPlacePredictions(
                {
                input: "pizza near",
                types: ['(cities)'],
                componentRestrictions: {country: 'fr'}
                }, 
                callback);
    

    支持四种类型:企业的“机构”、地址的“地理编码”、行政区域的“(地区)”和地方的“(城市)”。

    或者,如果你想使用 geyQueryPredictions(),你可以做以下技巧(但这不是一个好方法):

    {input: 'pizza near' + ',AR-M'}

    其中“AR-M”是阿根廷门多萨的邮政编码。 (我住的地方)看看你所在位置的邮政编码。

    当您展示预测时,请执行以下操作:

    for (var i = 0, max = predictions.length; i < max; i++) {
        var address = predictions[i].description.replace(/AR-M,/g, '');
            ...
        }
    

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      目前不支持,支持的请求参数请见reference documentation

      如果您认为这是一个有用的功能,请添加Places API - Feature Request

      【讨论】:

      猜你喜欢
      • 2020-12-31
      • 1970-01-01
      • 1970-01-01
      • 2016-11-23
      • 2018-07-10
      • 1970-01-01
      • 2010-12-12
      • 2012-09-22
      • 2018-10-23
      相关资源
      最近更新 更多