Google Places API


#1

I’m having some problems with places api. I need to return the reviews from nearby places. I’ve read the places API, but nowhere can I find the ‘reviews’ parameter. When I try to access it with javascript, for example

console.log(place.reviews);

It returns undefined. Am I calling it wrong? And here’s a pic when I just console log (places):


There is no “reviews”.

The following code marks all the nearby places on the map, and prints the names and ratings in an ul.

function createMarker(place) {
var placeLoc = place.geometry.location;
var listItem = document.createElement('li');
var star = document.createElement('i');
var value = document.createElement('p');
value.className = 'float-right mr-2';
value.innerText = place.rating;
star.className = 'fas fa-star float-right';
listItem.className = 'list-group-item';
listItem.innerText = place.name + " ";
for(var i = 0; i < place.rating; i++) {
    listItem.appendChild(star)
}
listItem.appendChild(value);
restUl.appendChild(listItem);

console.log(place.reviews)

var marker = new google.maps.Marker({
  map: map,
  position: place.geometry.location
});

google.maps.event.addListener(marker, 'click', function() {
  infowindow.setContent(place.name);
  infowindow.open(map, this);
});
}

And as you can see, I’m trying to console log the reviews (just for now) but it doesn’t work. Everything else works just fine.


#2

So… what API are you actually calling?
Because… The Place Search Results API doesn’t list ‘reviews’ as a field.


#3

It’s this one:
https://maps.googleapis.com/maps/api/js?key=…&libraries=places"


#4

Misread your opening post a bit, so let me respond directly to that…

That’s because there isn’t one. So, no, you’re not calling it wrong, it… doesn’t exist. So there’s nothing to call.


#5

reviews[] a JSON array of up to five reviews. If a language parameter was specified in the Place Details request, the Places Service will bias the results to prefer reviews written in that language. Each review consists of several components:.

I pulled that from places documentation. You can see it here also:
https://developers.google.com/places/web-service/details


#6

I honestly don’t get it. Should I call a different library in the script tag? And if so, what library then?


#7

Which is a different API than the one you’re referencing.
If you’ve read that API, it gives you examples of what URL you need to call.


#8

So I should call that inside a script tag?
Sorry for this dumb questions, I’m new to api’s


#9

Oh you’re using the Library, rather than the API. See, that’s where we’re talking at cross purposes.
https://developers.google.com/maps/documentation/javascript/places#place_details


#10

Yup. Thank you, I will check it out


#11

Make sure you check out the Pricing documentation as well. Understand what you’re getting into.


#12

Will do. Api’s are hard for a newbie hahah


#13

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.