【发布时间】:2015-06-26 08:58:08
【问题描述】:
JS API,不是网络服务:
我无法显示包含在地点详情回复中的 0-5 条评论: https://developers.google.com/maps/documentation/javascript/places#place_details_responses
到目前为止,我已经能够显示这些项目:
- details.name
- details.rating
- details.open_now
- details.formatted_address
- details.types
- details.formatted_phone_number
但当我尝试显示 details.reviews 时,它只会显示:
[对象对象],[对象对象],[对象对象],[对象对象],[对象对象]
有没有人成功展示评论?
function createMarker(place) {
var image = 'img/marker.png';
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
icon: image,
position: place.geometry.location
});
var request = { reference: place.reference };
service.getDetails(request, function(details, status) {
google.maps.event.addListener(marker, 'click', function() {
if (status == google.maps.places.PlacesServiceStatus.OK) {
// Replace empty spaces in navigation link with + symbols
var navLink = details.formatted_address;
navLink = navLink.replace(/\s/g, "+");
$('.navLink').html(navLink);
// Match Rating bar width to rating number
var ratingWidth = (details.rating*20)+"px";
$('.rating-bar > span').css('width', "'"+ratingWidth+"'");
var contentStr = '<h5 class="info-window-title">'+details.name+'</h5><ul class="info-window">';
if (!!details.rating) contentStr += '<li>Rating: <div class="rating-bar"><span style=width:'+ratingWidth+'></span></div><strong>'+details.rating+'</strong></li>';
if (!!details.open_now) contentStr += '<li class="open-now">'+details.open_now+'</li>';
contentStr += '<li>'+details.formatted_address+'</li>';
contentStr += '<li class=gray>'+details.types+'</li>';
// Check for platform to send appropriate app link
if ((navigator.platform.indexOf("iPhone") != -1)) {
contentStr += '<li class="link"><a class=navLink href=http://maps.apple.com/?daddr=Current+Location&saddr='+navLink+'><i class="fa fa-automobile"></i> Get Directions</a></li>';
} else {
contentStr += '<li class="link"><a class=navLink href=https://www.google.com/maps/dir/Current+Location/'+navLink+'><i class="fa fa-automobile"></i> Get Directions</a></li>';
}
if (!!details.formatted_phone_number) contentStr += '<li class="link"><a href="tel:'+details.formatted_phone_number+'"><i class="fa fa-phone"></i> '+details.formatted_phone_number+'</a></li>';
if (!!details.reviews) contentStr += '<li>'+details.reviews+'</li>';
contentStr += '</ul>';
infowindow.setContent(contentStr);
infowindow.open(map,marker);
} else {
var contentStr = "<h5>No Result, status="+status+"</h5>";
infowindow.setContent(contentStr);
infowindow.open(map,marker);
}
});
});
}
【问题讨论】:
-
请提供一个Minimal, Complete, Tested and Readable example 来证明这个问题。
标签: google-maps-api-3 google-places-api