google-maps-api-3google-places-api

Google Places Api from nodejs - set language


I am try to write a script to access the new google places API.

Based on the examples in the docs, I can get the following to work

curl -X POST -d '{
  "textQuery" : "101 Gowrie, Amsterdam"
}' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: ...' \
-H 'X-Goog-FieldMask: places.displayName,places.formattedAddress' \
'https://places.googleapis.com/v1/places:searchText'

But in my nodejs script I have what I think is the same:

fetch("https://places.googleapis.com/v1/places:searchText", {
  method: "POST",
  body: JSON.stringify({ textQuery: "101 Gowrie, Amsterdam" }),
  headers: {
    "Content-Type": "application/json",
    "X-Goog-Api-Key": apiKey,
    "X-Goog-FieldMask": "places.displayName,places.formattedAddress"
  }
}).then(res => res.json()).then(console.log).catch(console.log)

But then I get an error

{
  error: {
    code: 400,
    message: "Invalid language_code: '*'. See full list of supported languages at https://developers.google.com/maps/faq#languagesupport.\n",
    status: 'INVALID_ARGUMENT'
  }
}

I have no * in my query, and want english results, so I am confused


Solution

  • I found the answer at https://developers.google.com/maps/documentation/places/web-service/text-search#languagecode which adds languageCode to the body