1

I have developed an application that is powered by Google Places API. The problem is the places are loading when running locally but not after deploying it on google cloud. I am using a default keyword to fetch the desired results but surprisingly it is not working after its deployed. I tried changing the keyword but still, it returns 0 results. Please have a look at my code below

await axios
    .get("https://maps.googleapis.com/maps/api/place/nearbysearch/json", {
      params: {
        key: process.env.GOOGLE_PLACE_API_KEY,
        location: req.body.ll,
        radius: 20000,
        keyword: "popular destinations near me",
      },
    })

and the response I get

{ html_attributions: [], results: [], status: 'ZERO_RESULTS' }

Postman request of the same works without any issue

enter image description here

and the same request sent with a raw JSON data, I am getting an error

{
        "key": "my key",
        "location": "my location",
        "radius": "20000",
        "keyword": "popular destinations near me"
}
{
  "error_message": "You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account",
  "html_attributions": [],
  "results": [],
  "status": "REQUEST_DENIED"
}

The same request sent using postman returns 20+ results. I have no clue what could possibly be wrong with the above request. Any help is appreciated, thanks.

ksa
  • 311
  • 1
  • 10
  • 29
  • I am certain missing some part, Can you copy-paste the API RAW request you made in the postman here? Let us see what is the difference between then.. – Shawn Di Wu Sep 07 '20 at 22:15
  • @ShawnDiWu I have edited my question with a screenshot of the postman. Please have a look at it. I did not send a raw request but let me try sending it and see how that works. Thanks. – ksa Sep 07 '20 at 22:27
  • params: { key: process.env.GOOGLE_PLACE_API_KEY, location: req.body.ll, radius: 20000, keyword: "popular destinations near me", <- remove the comma }, – Shawn Di Wu Sep 07 '20 at 22:35
  • I tried but that didn't work as well. – ksa Sep 07 '20 at 22:42
  • add [error handle](https://javascript.info/async-await#error-handling) in your code to see what error pop-out. – Shawn Di Wu Sep 07 '20 at 22:47
  • sure thing. But there are no errors and in fact, it gives me status code 200 and returns an empty data set. – ksa Sep 07 '20 at 22:52
  • could you try to check the logs (all the logs not just errors)? I suspect some cross-origin problems. – sonkatamas Sep 07 '20 at 23:10
  • @sonkatamas, I have enabled CORS as a middleware. Moreover, the same request is working locally but not when it is deployed. I will check the logs as well and see there is anything abnormal. – ksa Sep 07 '20 at 23:14
  • btw, is it an api or do we have a frontend here? – sonkatamas Sep 07 '20 at 23:15
  • there is a frontend as well. – ksa Sep 07 '20 at 23:17
  • it seems the [Place Types](https://developers.google.com/places/web-service/supported_types) is required. Add type and try again ? for example type: restaurant – Shawn Di Wu Sep 08 '20 at 00:51
  • let me know if it helps, it seems there is documentation issue – Shawn Di Wu Sep 08 '20 at 00:51
  • @ShawnDiWu, thanks for reminding me of using place type. It works now. But, I am a little surprised here. I am sending 3 separate requests with different keywords like `popular destinations near me`, `Hiking near me`, and `Recreational Activities`. For some reason, the first 2 keywords are not returning any results unless the place type is defined. The 3rd one works fine without mentioning anyplace type. – ksa Sep 08 '20 at 02:36

1 Answers1

1

The Place API Place Search Nearby Search requests required parameters which are key, location, and radius. There are optional parameters you can input too, they are keyword(not keywords), language, minprice&maxprice, name, The name field is no longer restricted to place names. Values in this field are combined with values in the keyword field and passed as part of the same search string. We recommend using only the keyword parameter for all search terms. opennow,rankby,type,pagetoken.

So you cannot assign more than one keyword to your request.

Shawn Di Wu
  • 460
  • 2
  • 9