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

Below is the getQueryPredictions example given by google

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

Is there a way to restrict results for a specific country/city/state?

The other function/component has ability to do this

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

Answers


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.


Need Your Help

Mocking $modal in AngularJS unit tests

unit-testing angularjs angular-ui-bootstrap

I'm writing a unit test for a controller that fires up a $modal and uses the promise returned to execute some logic. I can test the parent controller that fires the $modal, but I can't for the life...

Android ListView Background Color Changes on Scroll - colorCacheHint Not Fixing Issue

android listview background-color

So I'm using a custom listview through an adapter, and on my Nexus 7 everything looks great, but on my HTC Incredible 2 I'm running into an issue where my background color changes. Here's my XML file