Introduction to Geocoding

Introduction to Geocoding

This article is an introduction to Geocoding, basis about geocoding and solutions related to geocoding for your business and product development.


For your information, geocoding is a process that converts addresses into geographic coordinates on this planet, Earth. Usually, the coordinate consists of two values:

  • longitude
  • latitude.

If you want to provide any feature that relates to users’ location, then geocoding is necessary. For example:

  • Sort all places from nearest to farthest, so-called “sort by distance“.
  • Find all places or users within 15km radius from a specific location.
  • …etc.

Geocoding is pretty much useful for implementing those features.

Another relating terms, “reverse geocoding“, which reverse the geocoding, that is, to convert geographic coordinates into real addresses.

But, the question is, “how do I get such data for geocoding?”

There are two solutions:

  1. Use a geocoding service provider, such as: Google Geocoding API
  2. Build yourself a geocoding database.

Solution 1: Use a geocoding service provider

This solution is very easy to implemented since it just requires some sorts of API calling and parses results into useful pieces of information.

Check out the example from the API page.

Given this API call:,+Mountain+View,+CA&key=YOUR_API_KEY

The JSON response will show everything about the address “1600 Amphitheatre Parkway, Mountain View, CA

   "results" : [
         "address_components" : [
               "long_name" : "1600",
               "short_name" : "1600",
               "types" : [ "street_number" ]
               "long_name" : "Amphitheatre Pkwy",
               "short_name" : "Amphitheatre Pkwy",
               "types" : [ "route" ]
               "long_name" : "Mountain View",
               "short_name" : "Mountain View",
               "types" : [ "locality", "political" ]
               "long_name" : "Santa Clara County",
               "short_name" : "Santa Clara County",
               "types" : [ "administrative_area_level_2", "political" ]
               "long_name" : "California",
               "short_name" : "CA",
               "types" : [ "administrative_area_level_1", "political" ]
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
               "long_name" : "94043",
               "short_name" : "94043",
               "types" : [ "postal_code" ]
         "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
         "geometry" : {
            "location" : {
               "lat" : 37.4224764,
               "lng" : -122.0842499
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 37.4238253802915,
                  "lng" : -122.0829009197085
               "southwest" : {
                  "lat" : 37.4211274197085,
                  "lng" : -122.0855988802915
         "place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
         "types" : [ "street_address" ]
   "status" : "OK"

However, it has drawbacks, it is not free. Of course, “there’s no such thing as free lunch”. Let see the Google Geocoding API

Let’s take the pricing for Google Geocoding API as sample.

Pricing for Google Geocoding API
Pricing for Google Geocoding API

It costs per request and for the first 100k requests, it costs totally around $0.005 * 100,000 = $500.

For next 400k requests, it costs $0.004 * 400,000 = $1600.

So, the first 500k requests of the month will cost you: $500 + $1600 = $2100.

If your services or products can cover this monthly cost, then you should have no worry.

But for small businesses, it might get hard to cover this monthly bill.

Honestly to tell, I like this API because it provides many details about location, so developers build more cool features around.

Solution 2: Build yourself a geocode database

If you think using external service API for geocoding is too expensive for your products, then you can start thinking to build a geocode database.

You might ask, how to get such info to put into database? 

I can tell you this, you can grab many information for free on many websites, but you need to take care of licenses or some sorts of agreements on terms from the datasource providers.

For references, you can take data from this service:

They provides most common data along with frequent updates, and it’s free.

However, their databases are much as big as Google. It means you need to take some considerations when building your apps. For examples:

  • Do you really need to get exact coordinate of a specific location? Does extending it to a larger area affect business requirements? Instead of calculating from a street address, use district code.
  • Do you need the exact measurement? 
  • Do you need to provide measurement for globe or just for local area?
  • …etc.

After answering with all considerations, you can decide if it is good to build a geocode database.

Extra Solution: A combining solution

The combination of both solution 1 and 2 is possible and I think it is reasonable for most products and services.

For example: you can think of making request to external API services to get data and store into databases. Later on, you can make queries from databases to handle calculation as necessary.

Something like that would work. This totally depends on how design the system and implement the technical solution.


The choice is yours to make. Both solutions have pros and cons, what you need to take considerations if geocoding really fits your business and users’ needs.

Hope this article provides you some sorts of understanding the geocoding and solutions to work with it.