19

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?

pjpscriv
  • 866
  • 11
  • 20
  • You can have the map on the page but don't give height and width to map_canvas. This way map will not be visible and search will work. – ihimv May 29 '15 at 05:00

1 Answers1

14

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);
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
relic
  • 1,662
  • 1
  • 16
  • 24
  • 2
    Does anyone know if this is allowed via terms? According to [this](https://developers.google.com/places/web-service/policies) page **"If your application displays Google Places API Web Service data on a page or view that does not also display a Google Map, you must show a "Powered by Google" logo with that data"** But why do they force you to specify an html elemnt? – TacticalMin Jan 12 '17 at 19:10