The demo shows calling Google Maps Platform APIs from Google Cloud Functions.
- Cloud Functions (Node 10)
- Function Framework for local development.
- Google Maps Services (Node.js Client)
- Directions API
- TypeScript
- Google Maps Types: https://www.npmjs.com/package/@types/google__maps
- Google Cloud Functions Server (Express): https://www.npmjs.com/package/@types/express
First install dependencies:
npm i
Then in one tab continually build the project with this command:
npm run build
In another tab, start the web server (and watch if the source code changes):
API_KEY=<KEY> npm run watch
This uses npm-watch
with the functions-framework
to auto re-build the server after changes.
Go to http://localhost:8080
to run your Google Cloud Function locally.
Here are some example URL requests:
http://localhost:8080/directions?mode=driving&origin=37.7841393,-122.404467
http://localhost:8080/origins?origin=6
http://localhost:8080/places?origin=37.7841393,-122.114167
To create an API key, use the Cloud Console credentials page:
https://console.cloud.google.com/apis/credentials
More detailed instructions can be found in the "Get API Key" guide.
After creating an API key, enable these APIs:
You must create a .env.yaml
with your API Key:
API_KEY=AIsdfyCnTEiLTroDN14NTtpPm1n7jrBR844ID4A
You can deploy this project to Google Cloud Functions by running the following script:
gcloud config set project $MY_PROJECT
sh deploy.sh