Mads Ohm Larsen
Mads Ohm Larsen

Reputation: 3745

Filter by type in Google AutocompleteService

I want to filter away establishments in my autocomplete service.

I have tried

var service = new google.maps.places.AutocompleteService;
var request = {
  "input": "Nørregade",
  "componentRestrictions": { "country": "dk" },
  "types": ["(cities)", "(regions)", "geocode"]
};
service.getPlacePredictions(request, function(predictions, status) {
  console.log(status) # => INVALID_REQUEST
});

(http://jsfiddle.net/gdk0j9eg/1/)

Following this link (https://developers.google.com/maps/documentation/javascript/reference#AutocompletionRequest) it seems that the autocomplete service does indeed take these types.

What am I doing wrong here?

Upvotes: 0

Views: 1074

Answers (1)

geocodezip
geocodezip

Reputation: 161384

See the documentation, you are only allowed to use a single type or type collection:

You may restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter. The parameter specifies a type or a type collection, as listed in the supported types below. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the geocode and establishment types, but note that this will have the same effect as specifying no types.

Upvotes: 1

Related Questions