21

I need a POI API that returns ratings, photos, opening/closing times, etc and I thought Google Places API seemed to do what I want, but I am having some trouble with filtering: I want to use the autocomplete feature with multiple types for filtering.

Here is what I have:

var map;
var selectAttractionAutocomplete;
var selectCityAutocompleteOptions = {
    types: ['(cities)']
};

map = new google.maps.Map(document.getElementById('map-canvas'), {
    center: new google.maps.LatLng(-33.8665433, 151.1956316),
    zoom: 15
});

var inputsearchedCity = document.getElementById('input-searched-city');
selectCityAutocomplete = new google.maps.places.Autocomplete(inputsearchedCity, selectCityAutocompleteOptions);
selectCityAutocomplete.bindTo('bounds', map);

google.maps.event.addListener(selectCityAutocomplete, 'place_changed', function () {
    console.log(selectCityAutocomplete.getPlace());
});

How can I use multiple types?

I have tried pipes, commas, brackets... nothing works:

var selectCityAutocompleteOptions = {
    types: ['cities|point_of_interest']
};
pookie
  • 3,796
  • 6
  • 49
  • 105
  • 3
    According to the [documentation](https://developers.google.com/maps/documentation/javascript/3.exp/reference#AutocompleteOptions) _"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."_ – duncan Jul 25 '15 at 10:09
  • Although given it should accept an array of strings, to specify that you would need to do it like `types: ['cities', 'point_of_interest']` – duncan Jul 25 '15 at 10:10
  • 2
    I've tried commas, and 'cities' on its own doesn't work. 'cities' needs to be '(cities)'. – pookie Jul 25 '15 at 10:46

5 Answers5

11

If your are using in a query string, use the | separator. Remember that only 'geocode|establishment' is currently valid as a collection type, which is the same than not specifying any combined type.

See: https://developers.google.com/places/web-service/autocomplete#place_types

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.

Juangui Jordán
  • 6,091
  • 2
  • 35
  • 31
4

According to Google Documentation, point_of_interestis of type 2, which are not supported in the types filter of a place search, or in the types property when adding a place.

Verma
  • 8,199
  • 2
  • 15
  • 17
1

This question is partly answered in this thread.

First, the place type of "cities" it not supported. You can find a list of supported place types here.

There is no way to use multiple types at once. However, you can call the API twice in order to get similar results. For example:

var selectCityAutocompleteOptions1 = {
  types: ['zoo']
};
var selectCityAutocompleteOptions2 = {
  types: ['museum']
};

Based off of your description, though, it sounds like you want all points of interest results, without filtering by type. In that case you might want to use a Find Place Requests Place Search instead.

0

Encountered this recently. Answer is here Google Places Auto-Complete

types, which can either specify one of two explicit types or one of two type collections.

kylestephens
  • 326
  • 5
  • 15
-6
var request = {
    bounds: map.getBounds(),
    types: ['bar','park']
      //keyword: 'best view'
  };
sara k.
  • 1
  • 10