pookie
pookie

Reputation: 4142

Google Places API: How to use multiple types?

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']
};

Upvotes: 22

Views: 28368

Answers (5)

Christina.Codes
Christina.Codes

Reputation: 88

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.

Upvotes: 1

Juangui Jordán
Juangui Jordán

Reputation: 6597

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.

Upvotes: 12

kylestephens
kylestephens

Reputation: 336

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.

Upvotes: 0

 sara k.
sara k.

Reputation: 1

var request = {
    bounds: map.getBounds(),
    types: ['bar','park']
      //keyword: 'best view'
  };

Upvotes: -6

Verma
Verma

Reputation: 8459

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.

Upvotes: 5

Related Questions