谷歌地方的API解析为javascript
我有一个谷歌API的网址,有我想在我的网页上输出的JSON。谷歌地方的API解析为javascript
的URL包括ID和关键
https://maps.googleapis.com/maps/api/place/details/json?placeid=122&key=123-mg
现在我想在div id myoutput
打印出以下数据
"reviews" : [
{
"aspects" : [
{
"rating" : 3,
"type" : "overall"
}
],
"author_name" : "Justine OBRIEN",
"author_url" : "https://www.google.com/maps/contrib/104177669626132953795/reviews",
"language" : "en",
"profile_photo_url" : "//lh6.googleusercontent.com/-s6AzNe5Qcco/AAAAAAAAAAI/AAAAAAAAFTE/NvVzCuI-jMI/photo.jpg",
"rating" : 5,
"relative_time_description" : "2 months ago",
"text" : "Fabulous location. Wonderful warm welcoming reception. Excellent unique living Google wall entry. Sensational helpful kind people. Easy fast efficient help online plus with appointment on site. Super company always progressive plus innovative products and services for all businesses. Go Google Australia. Shine on! ",
"time" : 1474966415
},
我迄今试图
<div id="myoutput"></div>
<script>
(function() {
var myobject = "https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=AIzaSyCUc3pmryE8WMd7niIrHIN7cq_6ZUyI-mg";
$.getJSON(myobject, {
format: "json"
})
.done(function(data) {
$.each(data.items, function(i, item) {
$("<p>").attr("author_name", item.media.m).appendTo("#myoutpu");
if (i === 3) {
return false;
}
});
});
})();
</script>
和
<script>
(function() {
var myobject = "https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=AIzaSyCUc3pmryE8WMd7niIrHIN7cq_6ZUyI-mg";
$.getJSON(myobject, {
format: "json"
})
print myobject.dumps([s['formatted_address'] for s in result['results']], indent=2)
myobject["address_components"].long_name
})();
</script>
我怎么看不到author_name
打印出来?
你的方法似乎是在这种情况下CORS被封锁,所以你可以使用的地方图书馆,像这样:
<div id="map"></div>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&libraries=places&callback=initMap"></script>
<script>
function initMap() {
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4'
}, function(place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for(var i=0; i <= place.reviews.length; i++) {
console.log(place.reviews[i]);
}
}
});
}
</script>
的map
格在那里只是为了运作服务。循环是您逐一显示所有评论对象的地方。在那里你可以做你所需要的结果。 此外,您可以从链接中删除&callback=initMap
并在需要时运行该功能。
嗯,明白,生病尝试,并得到这个工作,看看有什么附加。感谢接受,如果我得到它的工作 –
它基本上是一样的东西,你只是使用一个正常的谷歌地图API的函数。如果你为此而苦恼,我很乐意帮助你。 – yomisimie
非常感谢你,生病回复很快(20分钟) –
从代码示例中删除您的密钥,并对其进行更改。 – yomisimie
它不是我的钥匙,但我会如此 –