Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PlacesService and the need of html node

<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/

like image 458
user455318 Avatar asked Mar 17 '23 08:03

user455318


1 Answers

(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.

like image 178
ejensler Avatar answered Mar 27 '23 23:03

ejensler