1

I need a way to request a particular ID from google places then return the data from that place to show the reviews using JavaScript.

I have found some code that does it on a google map but what I want is just the plain data so I can display it a testimonial-like format on a website.

Any idea how I can do this?

Ryan Mc
  • 833
  • 1
  • 8
  • 25

1 Answers1

1

I believe you are looking for the Place Details endpoint for the Places API Web Service.

Hit the endpoint like so:

https://maps.googleapis.com/maps/api/place/details/output?parameters

Parameters will be a string containing your access key, PlaceID, and (optionally) the desired response data type.

The output will be either json or XML, according to what you specify in your parameters. In the response there should be an array in the result object called 'reviews'.

Display and use the reviews as you would any other array of data you need in your application.

The documentation for this endpoint, linked above, is very helpful. If you need to locate the ID of a particular place in order to use the above endpoint, check out Place Search Endpoint.

Clayton Rothschild
  • 702
  • 1
  • 5
  • 15
  • Thanks, this is a helpful start, could you possibly give me an example of what the parameters would look like, or how to format them? – Ryan Mc Feb 10 '17 at 19:13
  • Sure, to request a json object you would send an [HTTP Get Request](https://stackoverflow.com/questions/247483/http-get-request-in-javascript) structured like so:`https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=YOUR_API_KEY` – Clayton Rothschild Feb 10 '17 at 19:24
  • Thanks, I did that using the link you provided but I can't seem to get a request object back. I get an error message saying 'No 'Access-Control-Allow-Origin' header is present on the requested resource.' I'm using MAMP on localhost. Any ideas? – Ryan Mc Feb 10 '17 at 19:29
  • It may be easiest to use jQuery.getJSON [Request the JSON object](https://stackoverflow.com/questions/12460378/how-to-get-json-from-url-in-javascript). – Clayton Rothschild Feb 10 '17 at 19:30
  • Is your API Key registered and plugged in? When you load content across hosts sometimes content is blocked to prevent XSS. That type of error is independent of your particular use-case, so you will be able to leverage answers on No-Access-Control-Allow-Origin elsewhere on SO to solve that problem. – Clayton Rothschild Feb 10 '17 at 19:33
  • I'm not sure, to be honest I don't fully understand how the API keys work – Ryan Mc Feb 10 '17 at 19:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/135420/discussion-between-ryan-mc-and-clayton-rothschild). – Ryan Mc Feb 10 '17 at 19:36