0

Seen some related answers, wasn't sure if they are still valid(2014):

Get Google Place Details Without Map

Need to use nearbySearch() with specified coordinates and radius but without displaying and map,just get JSON data and work with it.

even Docs show the use of map to initialize the service :

map = new google.maps.Map(document.getElementById('map'), {
      center: pyrmont,
      zoom: 15
    });

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

Any suggestions on how to do it without map as updated solution that apply to current terms ?

Eyal Solomon
  • 470
  • 1
  • 6
  • 15

1 Answers1

2

There are two ways to use nearbySearch of the Places API. The first (the one you are currently using) is the Places library that is part of the Maps Javascript API. The other one is the Web Service, which is what you are looking for:

https://developers.google.com/maps/documentation/places/web-service/search-nearby

You set the the options (radius, coordinates, json) as query parameters in the URL and it will return the data as JSON. You can use something like .fetch or axios to send the request.

Dharman
  • 30,962
  • 25
  • 85
  • 135
user299697
  • 78
  • 1
  • 3
  • 1
    exactly what i was looking for ! thanks mate – Eyal Solomon Mar 11 '22 at 18:27
  • 1
    An important note : this will only work on server-side, otherwise you will get this CORS error : No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled – Eyal Solomon Mar 12 '22 at 09:10