A practical guide to the Google Geocoding API
In this tutorial series, we are going to take a deep dive into Google Map's second most popular* API, the Google Geocoding API. I'll explain what its used for, go through several worked examples and end each blog post with a working demo and source code that you can use in your own projects. We’ll also look at two related APIs: the Address Validation API, which helps identify and correct bad addresses, and Building Outlines and Entrances, which allows you to display a building’s footprint and entrances on a map.
Part 1: A practical guide to the Google Geocoding API (this article)
Part 2: Forward geocoding: Turn addresses into coordinates
Part 3: Google Maps reverse geocoding: Get addresses from coordinates
Part 4: Google Address Validation API: Better than USPS?
Part 5: Google Maps Building Outlines and Entrances API
* The #1 Google Maps API is of course the Maps Javascript API, which is used to render map tiles on the web.
What is the Google Geocoding API?
The Google Geocoding API is a web service that converts addresses - like "555 West Hastings Street, Vancouver BC, Canada", into geographic coordinates such as (49.2846966, -123.11258). It also supports the reverse process, turning latitude and longitude coordinates into human readable addresses or place names from the Google Maps database.
You can try this yourself on Google Maps (https://www.google.com/maps) by entering an address in the search bar and noting the latitude and longitude that appear in the URL. This process is called forward geocoding (or geocoding for short).
Reverse geocoding does the opposite - it converts a geographic location into a human readable address. To try it on Google Maps, click and hold anywhere on the map until a small marker appears. The address will then show up in a pop-up window at the bottom of the screen.
Of the two, forward geocoding (address 👉 coordinates) is generally more popular because it often is the first step in turning real world addresses into usable data for navigation, planning, and analytics.
What is geocoding used for?
Geocoding is essential when you need to display an address on a map or provide location data to an API. Many APIs, such as the Google Weather API or the Google Maps Route Optimization API (GMPRO), require GPS coordinates as input. For example, a delivery management tool might use forward geocoding to convert customer addresses into precise coordinates before sending them to GMPRO to generate optimized delivery routes.
Reverse address geocoding on the other hand, is used to convert GPS coordinates into readable location names for various applications such as location based services (e.g. weather apps displaying your current area), asset tracking (e.g. Apple’s FindMy app showing where you left your AirTags), and geotagging (e.g. social media platforms tagging photos with specific locations for easier discovery and context).
What's the difference between the Google Geocoding API and Autocomplete?
Both the Google Geocoding API and Places Autocomplete return the latitude and longitude for a given address. However, they serve different purposes: the Geocoding API is ideal for processing address text strings stored in a file or database, while Autocomplete is designed for user input - helping users select the correct address or place name from a searchable list. For example, a delivery management system might use the Geocoding API to process a batch of uploaded addresses, whereas an e-commerce site would use Autocomplete to guide customers in entering their delivery address during checkout.
How to get a Google Geocoding API key
To begin using the Geocoding API, you first need to set it up in the Google Cloud Console. Create a new project at https://console.cloud.google.com/ and name the project geocoding-api-demo
. Click [CREATE].
To enable the Geocoding API, navigate to the APIs & Services page by selecting it from the menu on the left. Then, click [+ Enable APIs and Services] and search for "Geocoding API".
Click on the [Geocoding API] link and hit the [Enable] button.
Click [Save]. If you return to the Keys and Credentials page, you can find your new API key by clicking the [Show Key] link on the right.
Google Geocoding API examples
The Geocoding API is easy enough to use. Once you have an API key, replace {GOOGLE_MAPS_API_KEY} with it in the examples below, copy the full URL, and paste it into your browser’s address bar. Press [Enter], and the response will appear directly in your browser.
Forward geocoding request
Method: GET
https://maps.googleapis.com/maps/api/geocode/json?address=555+west+hastings+street+vancouver&key={GOOGLE_MAPS_API_KEY}
Response
Reverse geocoding request
Method: GET
https://maps.googleapis.com/maps/api/geocode/json?latlng=49.2846966,-123.1119349&key={GOOGLE_MAPS_API_KEY}
Response
Is the Google Geocoding API free?
No, the Geocoding API is not completely free. Pricing starts at $5 per 1,000 addresses geocoded (CPM). However, Google offers a generous free tier that includes 10,000 geocoded addresses per month enough to support most mid-sized delivery operations without incurring any charges.
Google Geocoding API pricing
Like other Google Maps Platform APIs, the Geocoding API uses a pay-as-you-go pricing model. Customers are billed based on the number of addresses sent to the API. The first 10,000 addresses each month are free, and beyond that, the cost per 1,000 addresses (CPM) depends on the total monthly volume.
Monthly addresses | Cost per 1,000 addresses |
---|---|
Up to 10,000 | Free |
10,000 to 100,000 | $5.00 CPM |
100,000 to 500,000 | $4.00 CPM |
500,000 to 1 mil | $3.00 CPM |
1 mil - 5 mil | $1.50 CPM |
5 mil + | $0.38 CPM |
If you are dealing with high usage volumes, you can work with a Google Maps partner for volume discounts. See the official pricing page for details.
Can I cache Google Maps geocoding data?
Officially, no. The Google Maps Terms of Service clearly states:
5.3 Caching. Customer may temporarily cache latitude (lat) and longitude (lng) values from the Geocoding API for up to 30 consecutive calendar days, after which Customer must delete the cached latitude and longitude values.
But in practice everyone does it anyway and there's no way for Google to enforce this rule. A popular way to reduce geocoding costs is by first checking if the address has been "seen". If it has, reuse the stored latitude and longitude. If it's a new address, geocode it once and save both the address and its coordinates to a database for future use.
Google Geocoding API alternative
If you're considering alternatives to the Google Maps Geocoding API, several competing services such as Mapbox, HERE Maps or Tom Tom - offer solid options at a lower cost. For example, Mapbox's paid tier starts at just $0.75 per 1,000 requests (CPM) and includes 100,000 free geocodes per month. However, Google remains the top choice for many due to the superior accuracy and freshness of its address data. For last mile logistics businesses operating on tight margins, the cost of a failed delivery due to an incorrect address can far outweigh the $0.005 it costs to get accurate geocoding from Google.
What you'll learn in this tutorial series
The Google Geocoding API is a mainstay of the Google Maps Platform. By the end of this tutorial series, you'll be able to:
- Convert any address into its latitude and longitude
- Reverse geocode GPS coordinates into human-readable addresses and place names
- Use the Google Address Validation API to check if an address is deliverable
- Display building outlines and mark entrances on a map
👋 As always, if you have any questions or suggestions for me, please reach out or say hello on LinkedIn.
Next: Part 2: Forward geocoding: Turn addresses into coordinates