Willem Ghijsen
Willem Ghijsen

Reputation: 215

Google Places Autocomplete not returning results for some types

I am using google places autocomplete to suggest schools for my users. The autocomplete is simply not working when I specify the type as school, or point_of_interest as another example. When I specify the type as establishment or geocode the autocomplete works fine.

I am using Ionic 4 and my autocomplete code looks like this:

profile.page.ts

    getHighSchoolAutocomplete() {
          let input = this.highSchoolText;
          this.myHSAutocomplete = new google.maps.places.Autocomplete(input.nativeElement, {types: ['school']});
          google.maps.event.addListener(this.myHSAutocomplete, 'place_changed', () => {
            // retrieve the place object for your use
            let place = this.myHSAutocomplete.getPlace();
            console.log('initPlaces place getHighSchoolAutocomplete', place.formatted_address);
            this.addressHS = this.tmpParentInfo.get('myHighSchool').setValue(place.formatted_address);
          });
        }
      }

profile.page.html

    <h5 class="ion-padding-start">High School:<br></h5>
    <input type="text" #highSchoolText formControlName="myHighSchool" class="highSchoolClass" id="googlePlaces1" class="ion-padding-start">

index.html (the googlemaps api string)

 <script src="https://maps.googleapis.com/maps/api/js?v=3.26&key=MY_API_KEY&libraries=places"></script>

I have already tried the fixes here and no dice: Google Places Autocomplete not showing up

Upvotes: 1

Views: 1359

Answers (1)

evan
evan

Reputation: 5701

It's expected that Autocomplete doesn't work because school is not a supported type for this service.

This is why it works when you specify establishment or geocode instead, as these are supported types. You can only restrict results to school type (or any other type listed in table 1) in Place Search requests.

Hope this helps.

Upvotes: 0

Related Questions