<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&language=pt-PT" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var request = {
placeId: 'ChIJO_PkYRozGQ0R0DaQ5L3rAAQ'
};
service = new google.maps.places.PlacesService(document.getElementById('places'));
service.getDetails(request, callback);
function callback(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
console.log(place);
}
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body> <div id="places"></div> </body>
</html>
我的代码运行良好,但我不知道为什么需要使用
PlacesService(document.getElementById('some id'));
如果我只使用 PlacesService();
我会收到错误。 html_attributions 为无:html_attributions: Array[0]length: 0
那么,我的代码没问题吗,或者我应该做什么?
最佳答案
(如果 6 个月后你还没有弄清楚)你的代码将会工作并且 should adhere to Google's policies surrounding the PlacesService .
根据我的理解,“归因”是将信息来源归因于特定合作伙伴的某种信息,例如来自 Yelp 的评论(我不知道他们是否与 Yelp 合作,但这就是想法) 。显然,合作伙伴希望信息的最终消费者知道是谁提供的。
这个想法是,当您使用 PlacesService 执行搜索时,如果有附加 map ,它将自动呈现“属性”。因此,如果您没有 map ,库将尝试将属性呈现到 html 节点中。隐藏该节点(或 map )是违反政策的。
需要注意的是,在使用该库时,html_attributions
数组可能并不总是为空,但只要您在 DOM 中提供一个可见节点,没问题,因为库会自动用属性填充节点(如果属性存在)。
关于google-maps - PlacesService和html节点的需要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27990005/