How to hit the Google Maps Platform API

Google Maps Platform APIs each live on their own host. The Geocoding API takes the key in the query string; the newer Places and Routes APIs take it in X-Goog-Api-Key and require X-Goog-FieldMask to say which fields to return.

Authentication

Create an API key in the Google Cloud console and enable each API you use. In the examples it's written {{GOOGLE_MAPS_API_KEY}}.

Full reference: https://developers.google.com/maps/documentation

Geocode an address

curl "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key={{GOOGLE_MAPS_API_KEY}}"
Run in PostTaco

Search places (Places API New)

curl -X POST https://places.googleapis.com/v1/places:searchText \
  -H "X-Goog-Api-Key: {{GOOGLE_MAPS_API_KEY}}" \
  -H "X-Goog-FieldMask: places.displayName,places.formattedAddress,places.rating" \
  -H "Content-Type: application/json" \
  -d '{"textQuery": "tacos in Boulder, CO"}'
Run in PostTaco

Compute a route (Routes API)

curl -X POST https://routes.googleapis.com/directions/v2:computeRoutes \
  -H "X-Goog-Api-Key: {{GOOGLE_MAPS_API_KEY}}" \
  -H "X-Goog-FieldMask: routes.duration,routes.distanceMeters" \
  -H "Content-Type: application/json" \
  -d '{"origin": {"address": "Boulder, CO"}, "destination": {"address": "Denver, CO"}, "travelMode": "DRIVE"}'
Run in PostTaco