【发布时间】:2019-07-20 19:15:07
【问题描述】:
找不到任何 google.maps.places.PlacesServices() 的示例,它从具有组件限制的输入字段进行搜索,就像自动完成一样。 Google site只有参考资料,没有例子
我在下面有这个但收到一个错误提示
TypeError: 无法读取未定义的属性“innerHTML”
和
TypeError: 无法读取属性 'findPlaceFromQuery' of null
findLocationFromPlaces() {
this.placesService = new google.maps.places.PlacesService(this.cityInput);
const request = {
query: 'San Francisco',
fields: ['photos', 'formatted_address', 'name', 'rating', 'opening_hours', 'geometry']
};
this.placesService.findPlaceFromQuery(request
// {
// types: ['(cities)']
// // componentRestrictions: { country: this.countrySelected },
// // types: ['geocode'] // 'establishment' / 'address' / 'geocode'
// }
,
(results, status) => {
if (status === google.maps.places.PlacesServiceStatus.OK) {
}
else {
}
}
);
}
我的“this.cityInput”是
@ViewChild('city') cityInput: HTMLDivElement;
<input appGooglePlaces id="city" (onSelect)="setAddress($event)" (keydown.Tab)="onTabAway($event)" (focusout)="focusOutFunction($event)" (input)="onLocationChange($event)" [ngClass]="{'is-invalid': registerForm.get('city').errors && registerForm.get('city').touched}"
formControlName="city" class="form-control google-place-input" [placeholder]="placeholder">
【问题讨论】:
标签: javascript google-maps google-places-api googleplacesautocomplete