我一直在按照本指南使用 Google Place JavaScript 库来显示硬编码坐标半径 500 米内的餐馆列表。
这是我到目前为止所尝试的:
.ts
文件_
export class AmenityPage {
nearbyPlaces: any;
service: any;
map: any;
constructor(){
}
init_map(){
let here = new google.maps.LatLng(-1.3631861,36.6560394);
let request = {
location: here,
radius: [500],
type: ['restaurant']
}
this.service = new google.maps.places.PlacesService(this.map);
this.service.nearbySearch(request, this.callback);
}
callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
this.nearbyPlaces = [];
for (var i = 0; i < results.length; i++) {
//let place = results[i];
this.nearbyPlaces.push(results[i]);
}
}
}
}
这是.html
文件:
<ion-content>
<ion-list>
<ion-item *ngFor = "let place of nearbyPlaces">
<h3>{{place.name}}</h3>
</ion-item>
</ion-list>
...
</ion-content>
问题是,构建应用程序时没有显示任何文本,控制台日志上也没有出现错误。我不太精通 Ionic,所以我不知道我在代码中遗漏了什么。
有没有传统的方法呢?非常感谢任何有关如何解决此问题的建议和指导。