Google Places API Tutorial: Address Autocomplete, Place Search and Details (with Code)
Learn the Google Places API (New): set up a key, add address autocomplete to checkout forms, search places by text or nearby, fetch place details with field masks, and keep your bill under control.

Table of contents
What you can do with the Places API
- Autocomplete: suggest addresses and places as users type — great for checkout and sign-up forms.
- Text Search: find places from a query like “dentist in Vijay Nagar Indore”.
- Nearby Search: list places of certain types around a location.
- Place Details: get address components, coordinates, opening hours, phone and ratings for a place ID.
- Place Photos: show photos for a place, with required attributions.

Set up your project and key

- 1
Create a Google Cloud project: and enable billing (Google offers free monthly usage for many SKUs).
- 2
Enable the API: turn on Places API (New) in the API library.
- 3
Create an API key: in APIs & Services → Credentials.
- 4
Restrict the key: limit it to your website domains (HTTP referrers) or app package, and to the Places API only.
- 5
Set budget alerts: create a billing budget so unexpected usage is caught early.
Tip: Use separate keys for the browser and the server. The browser key is visible to users, so it must be restricted to your domains.
Text Search with a field mask
The newer Places API asks you to list exactly which fields you need using a field mask. Fewer fields mean faster responses and, often, a cheaper SKU.
const res = await fetch("https://places.googleapis.com/v1/places:searchText", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Goog-Api-Key": process.env.GOOGLE_MAPS_KEY,
"X-Goog-FieldMask": "places.id,places.displayName,places.formattedAddress,places.location",
},
body: JSON.stringify({ textQuery: "dental clinic in Ujjain", languageCode: "en" }),
})
const { places } = await res.json()Address autocomplete for checkout
- 1
Add the widget: use Google’s Place Autocomplete web component or JavaScript library, or call the Autocomplete endpoint from your own UI.
- 2
Bias to your area: restrict results to India (or your delivery countries) and bias towards your city.
- 3
Use session tokens: group the typing requests and the final details request into one session to reduce costs.
- 4
Fetch details: when the user selects a suggestion, request only the address components and location you need.
- 5
Fill the form: map components to street, city, state and pin code; let the user edit house and floor details.
Keep costs and compliance in check
“Field masks and session tokens are the two habits that keep a Places API bill small.”
- Request only needed fields: richer fields such as ratings and opening hours can cost more.
- Debounce typing: wait a moment after each keystroke before requesting suggestions.
- Cache place IDs: place IDs can be stored; check the terms for what other data may be cached.
- Show attributions: display Google’s attribution where required when showing Places data.
Topics
Umer Hasan
Co-Founder & CTO at Zapprex
Leads engineering, cloud infrastructure and AI automation at Zapprex Technologies, with 7+ years of full-stack and mobile experience.
Keep reading
All articlesHow to Build a SaaS Product: Multi-Tenancy, Billing, Auth and Architecture Explained Simply
The building blocks every SaaS product needs — tenants, roles, subscription billing, onboarding, audit logs and observability — explained for founders, with the decisions you must make early and the ones you can delay.
Shopify App (Plugin) Development Tutorial: Build, Test and Publish Your First Shopify App
A beginner-friendly tutorial for building Shopify apps: public vs custom apps, setting up with Shopify CLI, the Admin GraphQL API, theme app extensions, webhooks, billing and App Store review requirements.
Custom ERP vs Odoo vs Zoho: Which Is Right for Your Growing Business?
Off-the-shelf ERPs are fast to start but can become expensive and rigid as you grow. A practical comparison of Odoo, Zoho and custom ERP — and a simple framework to decide.
Questions readers ask
It is a paid API with free monthly usage thresholds for many SKUs. Costs depend on the endpoint and fields requested, so check the current pricing and set budget alerts.
Places API (New) is the current version with field masks, new endpoints and updated pricing. New projects should use it.
Yes. Call the Places API from your backend or use a maintained library, and restrict your key to your app’s package and signing certificate.
Have a project in mind?
Let's build something that moves your business forward.
Share your idea, process or problem — we will come back with a clear plan, timeline and cost range. No technical spec needed.
- Founder reply within 1 business day
- NDA on request · 100% code ownership
- Talk directly to the engineers
