PlacesService和html节点的需要 [英] PlacesService and the need of html node

查看:136
本文介绍了PlacesService和html节点的需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < HTML> 
< head>
< script src =http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places&language=pt-PTtype =text / javascript> ;< /脚本>
< script type =text / javascript>
函数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> < /体>

< / html>

我有这个代码很好用,但我不知道为什么我需要使用 p>

  PlacesService(document.getElementById('some id')); 

如果我只使用 PlacesService(); 我会收到一个错误。 html_attributions是none: html_attributions:Array [0] length:0



我该怎么办?



http://jsfiddle.net/c6p14g4d/

解决方案

(如果6个月后你还没有弄明白的话)你的代码可以正常工作,应遵守Google有关PlacesService的政策



从我的理解是,归因是某种信息将信息的来源归因于某个特定的合作伙伴,例如,来自Yelp的评论(我不知道他们是否与Yelp合作,但这就是主意)。显然,合作伙伴希望信息的最终消费者知道是谁提供的。



想法是,当您使用PlacesService执行搜索时,如果有附加地图它会自动呈现归因。因此,如果您没有地图,图书馆会尝试将归因变成html节点。隐藏该节点(或地图)违反了策略。

需要注意的是,在使用库时, html_attributions 数组在使用库时并不总是为空,但只要你在DOM中提供一个可见节点,你就可以了,因为如果库存在那里,库会自动填充节点。


<html>
    <head>
        <script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;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>

I have this code that works well, but i don't know why i need to use

PlacesService(document.getElementById('some id')); 

If i use only PlacesService(); I will get an error. The html_attributions is none: html_attributions: Array[0]length: 0

So, is my code fine, or what should I do?

http://jsfiddle.net/c6p14g4d/

解决方案

(If you haven't figured it out 6 months later) Your code will work and should adhere to Google's policies surrounding the PlacesService.

From my understanding, "attributions" are some sort of information attributing the source of the information to a particular partner, for example, a review from Yelp (I don't know if they partner with Yelp, but that's the idea). Obviously the partner wants the end consumer of the information to know who provided it.

The idea is that when you perform a search with the PlacesService, if there is an attached map, it will render "attributions" automatically. Thus, if you don't have a map, the library will attempt to render the attributions into an html node. Hiding that node (or the map) is against the policy.

It's important to note that the html_attributions array might not always be empty in all cases when using the library, but as long as you provide a visible node in the DOM, you're fine, since the library automatically populates the node with attributions if they are there.

这篇关于PlacesService和html节点的需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆