Google Places API - Passing Multiple "Types" into the Autocomplete Function

47 views Asked by At

I'm using the Autocomplete function with the Google Places API but when typing into the autocomplete form field I have, I'd like to filter by home and business addresses, so it would enable me to type my home or work address, but for some reason I can't parse multiple types into the "types" parameter.

My code is below:

var ac = new google.maps.places.Autocomplete(
    (document.getElementById('address_line_1')), {
        componentRestrictions: { country: ["uk"] },
        fields: ["address_components", "geometry"],
        types: ["address"],
    });

  ac.addListener('place_changed', function() {

    var place = ac.getPlace();

    var address_line_1 = place.address_components[0].long_name + ' ' + place.address_components[1].long_name;
    var address_town = place.address_components[2].long_name;
    var address_county = place.address_components[3].long_name;
    var address_postcode = place.address_components[6].long_name;

    $('input#address_town').val(address_town);
    $('input#address_county').val(address_county);
    $('input#address_postcode').val(address_postcode);

  });
}

I've tried changing:

types: ["address"]

to

types: ["address", "establishment"]

and

types: ["address, establishment"]

But nothing works. The documentation is here, but doesn't say anything about not being able to add multiple types - https://developers.google.com/maps/documentation/places/web-service/supported_types

Any guidance would be much appreciated. Even if I can't pass multiple types, surely there's a way around this? Thanks!

0

There are 0 answers