[英]is there anyway to limit display number to 2 reviews on google places using api
我正在使用 webflow 使用 Google API 在我的网站上显示 google 评论,目前,一切正常,但显示 5 条评论,我只想显示 2 条
我已经有一个代码来显示评论,但无论如何要添加我的代码以仅显示 2 条评论?
<script>
var map = document.getElementById('google-places');
function initMap() {
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: 'xxxxxxxxxxxxxxxxx'
}, function (places, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
reviewsArray = [];
reviewsArray.push(places.reviews);
for (var key in reviewsArray) {
var arr = reviewsArray[key];
for (i = 0; i < arr.length; i++) {
var review = arr[i];
var author = review.author_name;
var when = review.relative_time_description;
var comment = review.text;
var starNumber = review.rating;
var starPercentage = `${(starNumber / 5) * 100}%`;
console.log(starPercentage);
var profilePic = review.profile_photo_url;
// console.log(author + ', ' + when + ', ' + comment + ', ' + rating + ', ' + profilePic);
document.getElementById('google-places').innerHTML += ` ${author} ☆☆☆☆☆ ★★★★★
</div>
</div>
<div class="review-content-wrapper">
<div class="review-text">${comment}</div>
</div>
</div>
</div>
`
}
}
}
})
}
</script>
<!-- Replace XXX with your key that you created at https://console.cloud.google.com -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxx&libraries=places&callback=initMap">
</script>
似乎 Google 评论默认为 5 条评论(来源: 是否可以从 google place api 获取最新的 5 条 Google 评论? )。
你可以只使用前两个而忽略后三个吗?
你应该能够在你自己的代码中做到这一点; 它不依赖于 API; 例如,如果您使用 Jquery 或 PHP,您可以遍历数组并仅显示索引为 0 和 1 的评论,例如仅显示两者而忽略其余部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.