Google Maps Geocoding is part of Google’s developer APIs that allows developers to translate between human-readable location addresses to location coordinates. This means that your house address can be converted to its geographical location coordinates, defined in latitude and longitude. This is called geocoding. This API also supports reverse geocoding wherein a location coordinate pair can be converted to its approximate location address.
In this blog post, we will cover the basic use cases of geocoding and learn about how to test the Google Maps Geocoding API. Google Maps Geocoding is integrated with Rakuten Rapid API. So you can directly invoke the API from within the API console once you log on to your Rakuten Rapid API account.
In case you don’t have an account on Rakuten Rapid API, sign up now and get your universal API key to access the Google Maps Geocoding API and thousands of other APIs hosted on Rakuten Rapid API.
Table of Contents
- 1 When Do You Need Geocoding?
- 2 Overview of Google Maps Geocoding API
- 3 Google Maps Geocoding API in Action
- 4 Wrap Up On Google Maps Geocoding
When Do You Need Geocoding?
First, let’s take a look at some simple use cases of geocoding and reverse geocoding.
Geocoding is handy when you are collecting information about someone’s address location and want to point it on the map for navigating to that location. If you have used Google Maps, then you have used this feature quite often. Even logistics and supply chain companies rely on such service to track their assets and shipments globally.
Let’s assume that you are building an app that offers home services to customers. As part of that, you collect addresses of customers while booking an appointment for them.
Now there is a need to translate the customer’s address to location coordinates so that we can navigate to that location. Geocoding is the way to do it.
What about reverse geocoding?
Imagine that you run a security services company. Your company deploys security personnel across various customer locations. To ensure that everyone adheres to their assigned location, you also deploy a system in place to monitor them through their mobile phones.
However, since it is not possible to keep a watch on them all day, you opt for a system to log the position of each person. In this way, all the location coordinates of the field security personnel are captured and logged in a central system.
Here is a sample of how this position log might look like for a single user.
User_Id | Timestamp (MM-DD-YY HH:MM:SS | Latitude | Longitude
User1 | 11-02-2019 13:24:52 | 40.73061 | -73.95981
User1 | 11-02-2019 13:29:57 | 40.73051 | -73.95983
User1 | 11-02-2019 13:34:59 | 40.72007 | -73.94387
User1 | 11-02-2019 13:40:02 | 40.73010 | -73.92015
User1 | 11-02-2019 13:44:10 | 40.77031 | -73.34014
As you can see, the position of each user is logged every few minutes and recorded as his current location coordinates in latitude and longitude.
This is all good, but what if someday you have to track the whereabouts of this person? You would open his position log file and see a bunch of location coordinates without having any idea about the addresses of the places he visited. What you need is a way to convert those location coordinates to a meaningful street address.
This is reverse geocoding. That is, converting a location coordinate to its physical address location that contains some information to locate the place based on some identifiable names like the street, locality, city, state as well as the country.
Overview of Google Maps Geocoding API
Google Maps Geocoding supports both the operations and it is quite simple to use.
Head over to your Google Maps Geocoding API console and you can see the two API endpoints for reverse geocoding and geocoding.
Google Maps Geocoding API has a freemium pricing model, so you can opt for the BASIC subscription and make 500 API calls per month.
Google Maps Geocoding API in Action
Let’s take this API on a test drive.
Keep your API console open while we show you how to leverage Google Maps Geocoding to solve the two use cases on geocoding and reverse geocoding.
Performing Geocoding To Translate Customer Addresses to Location Coordinates
Select the ’Geocoding’ endpoint from the API Console and you will see the API parameters.
By default, the “address” field has a value of “164 Townsend St., San Francisco, CA”. If you hit the “Test Endpoint” button, you will get the following response.
You can find the location coordinates in the blue highlighted value within the JSON response. This is the approximate location coordinate of the address value that was passed in the “address” field of the API.
The API also returns the details of address components, contained in the address_components key, starting from the street name, all the way up to the country name.
Now if you recall our original use case for geocoding, we have got an app to capture the address of the customer. So the user keys in the address and then the app needs to translate that into actual location coordinates.
If you interface this App with the Google Maps Geocoding API’s ‘Geocoding’ endpoint, then for the address shown in the app screen, you will get this result.
There you are!
You got the location coordinates of the customer which can be saved for future navigation purposes. You can also verify this coordinate on Google Maps to confirm the address.
Performing Reverse Geocoding To Transform Position Logs of Field Personnel
Let’s now revisit our second use case of tracking the position of field personnel.
Here is one entry from the position log of a user that we saw earlier.
You already know the pain point of analyzing this log to figure out the actual location address of the user. By running this log entry through a script that extracts the location coordinates and calls the reverse geocoding endpoint, we can get the physical address of the user.
In this case, the script will invoke the ‘Reverse Geocoding’ endpoint with the “latlong” parameter set to location coordinates stored in the log entry.
As you can see, this location coordinates translate to an address in New York.
The API always returns multiple levels of addresses for the same location, each categorized as different location types, such as establishment, street address, and country, etc..
With this API response, the script can transform the position log messages to append the location address of the user.
Isn’t it much more readable now?
That’s the power of an API that instantly transforms raw data into useful information.
Wrap Up On Google Maps Geocoding
We have shown you two use cases where geocoding can be really helpful. Take a look at the API Details tab of Google Maps Geocoding API console for all the optional parameters that can be used with the endpoints.
In case you are looking for more options for geocoding, then you can browse our geocoding API collection. This collection has other APIs similar to Google Maps Geocoding for geolocation, IP geocoding and time zones, etc. This will get you some more ideas to mashup the APIs with your apps. Also, be sure to check out our Top 10 Maps & Geolocation APIs.
We can’t wait to see the awesome apps that you will build using this API so please share your ideas, feedback, and comments below. In case of any queries, our support team available to help you. Finally, if you liked this tutorial don’t forget to check our tutorial on Google Translate API. You may also like to check out our list of best translation APIs and speech to text APIs.
We will be back soon with yet another API tutorial from our catalog.