ksa
ksa

Reputation: 331

Google Places API returns 0 results after deploying on Google Cloud

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.

Upvotes: 1

Views: 232

Answers (1)

Shawn Di Wu
Shawn Di Wu

Reputation: 458

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.

Upvotes: 1

Related Questions