我必须使用Google Places API显示Google Places评论。 我已经找到了placeId,但不确定如何使用它来呈现评论。 有什么帮助吗?谢谢!
let storage = [];
let service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: userGeoLocation,
},
function(results, status) {
if (status !== 'OK') return;
for (let i = 0; i < results.length; i++) {
storage = {
position: results[i].geometry.location,
placeId: results[i].id,
}
}
});
$("#review").html(storage.placeId.review);
的新功能
答案 0 :(得分:0)
您最多可以在地点数据返回的评论节点中获得5条商业评论(如果存在);实际上,您可能会遵循以下原则:
// Fetching reviews
for (let i = 0; i < results.reviews; i++) {
var author = results.reviews[i].author_name;
var author_url = results.reviews[i].author_url;
var rating = results.reviews[i].rating;
var author_image = results.reviews[i].profile_photo_url;
var text = results.reviews[i].text;
$("#review").append(author ' + gave me ' + rating + ' stars and wrote: ' + text);
}
只要results.reviews.length> 0;我们需要进行审查;上面的片段将循环显示0-4,或1至5条评论(如果有);根据Google的示例,您只有几个变量可以使用,如以下示例所示:
"author_name" : "Robert Ardill",
"author_url" : "https://www.google.com/maps/contrib/106422854611155436041/reviews",
"language" : "en",
"profile_photo_url" : "https://lh3.googleusercontent.com/-T47KxWuAoJU/AAAAAAAAAAI/AAAAAAAAAZo/BDmyI12BZAs/s128-c0x00000000-cc-rp-mo-ba1/photo.jpg",
"rating" : 5,
"relative_time_description" : "a month ago",
"text" : "Awesome offices. Great facilities, location and views. Staff are great hosts",
"time" : 1491144016
您可以在此处了解更多信息: https://developers.google.com/places/web-service/details