【问题标题】:Google Places Autocomplete not returning results for some typesGoogle Places Autocomplete 不返回某些类型的结果
【发布时间】:2020-01-20 20:42:39
【问题描述】:

我正在使用 google 地方自动填充功能为我的用户推荐学校。当我将类型指定为学校或 point_of_interest 作为另一个示例时,自动完成功能根本不起作用。当我将类型指定为建立或地理编码时,自动完成工作正常。

我正在使用 Ionic 4,我的自动完成代码如下所示:

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(googlemaps api 字符串)

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

我已经在这里尝试了修复,但没有骰子: Google Places Autocomplete not showing up

【问题讨论】:

标签: angular typescript google-maps ionic4 google-maps-autocomplete


【解决方案1】:

预计自动完成功能不起作用,因为 school 不是此服务支持的类型。

这就是为什么当您指定establishmentgeocode 时它会起作用,因为这些 supported types。在地方搜索请求中,您只能将结果限制为 school 类型(或 table 1 中列出的任何其他类型)。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-04
    • 1970-01-01
    • 2017-08-22
    相关资源
    最近更新 更多