user1912899
user1912899

Reputation:

Get Google Place Details Without Map

I have a reference to a Google Place, and use the Javascript API to get the place details.

It works fine as long as there is a map on the page.

But if there is no map - I only want the place's details - it breaks because the variable map is not defined.

The documentation specifies:

"Place Details are requested with a call to the service's getDetails() method."

service = new google.maps.places.PlacesService(map);
service.getDetails(request, callback);

If I leave out the map variable, I get: "Uncaught TypeError: Cannot read property 'innerHTML' of undefined"

I can make a server-side request, but there is a limit to the number of times you can do that.

Is there a way in Javascript to get just the place details without a map?

Upvotes: 19

Views: 4969

Answers (1)

relic
relic

Reputation: 1704

After working with this for a bit, the solution I came up with was to create a new map object without appending it to the document. The API seems to be fine with this.

let map = new google.maps.Map(document.createElement('div'));

Then make your request, same as before with the dummy map obj.

this.googlePlaces = new google.maps.places.PlacesService(map);
this.googlePlaces.getDetails(request, callback);

Upvotes: 14

Related Questions