Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Places API: How to use multiple types?

Tags:

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']
};
like image 841
pookie Avatar asked Jul 25 '15 09:07

pookie


1 Answers

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.

like image 60
Juangui Jordán Avatar answered Sep 29 '22 09:09

Juangui Jordán