Google Places API - getQueryPredictions Restrict by Country/City/State?

不问归期 提交于 2019-12-03 13:14:22

This is currently not supported, for supported request parameters please see the reference documentation.

If you think this would be a useful feature please add a Places API - Feature Request.

Use this similar function (it's a bit more powerfull than getQueryPredictions):

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

Four types are supported: 'establishment' for businesses, 'geocode' for addresses, '(regions)' for administrative regions and '(cities)' for localities.

Or, if you want to use geyQueryPredictions(), you can do the following trick (but it's not a good way):

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

Where 'AR-M' is the Postcode of ARGENTINA, MENDOZA. (where I live) Just look at your location's postcode.

The, when you show the predictions, do:

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

Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!