Home > Blockchain >  Google Places suggestions based on coordinates without map
Google Places suggestions based on coordinates without map

Time:03-12

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 ?

CodePudding user response:

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.

  • Related