GEOSPATIAL ANALYSIS. DATA SCIENCE. ANALYTICS.PYTHON.

Getting Geocode of an Address Quickly Using Python

Geocoding is the process of translating text addresses into geographic latitude and longitude coordinates which in turn make it easy to manipulate and analyze massive amounts of geospatial data.

For a data scientist, knowing the geocode makes it easy to plot it in visualization and create other features, such as distances and time differences between two points.

Unlike other types of data, geospatial data benefits greatly from visualization as it makes apparent the occurrence of patterns in neighborhoods or local networks.

As such, businesses profit from the use of it but not if the process involves manually getting the geocodes.

While this process can be done using the open-source package, OpenStreetMap, Google Maps API may produce more accurate data for a wider range of addresses.

In this article, let us examine how to get these geocodes through Python and Google Maps API to speed up our data projects.

The use of Google Maps API comes with a charge and data scientists need to be aware of the pricing before using it.

To use the google maps API, we need to generate our very own API key to use this.

You will see here your dashboard.

STEP 2 — Create a New Project

To create a new project, follow the GIF above. The option to do this is found in the upper right corner, with a “Select a Project” text. Name the project to better manage current and future projects that involve Google APIs.

STEP 3 — Enable Google Geocoding

Browse the API Library to enable the geocoding service. This is named the “Geocoding API”.

STEP 4 — Create Credentials to Generate API Key

Once the Geocoding API service is enabled, go to the Credentials tab and choose “+Create Credentials”. Once the API key is created copy it to use in your Python code.

You can rename the API and restrict it to keep it safe. There is an edit option to do this under the “API Keys” table for each API key (the pencil sign).

To use the API Key, ensure that you have installed the googlemaps package:

pip install googlemaps

STEP 1 — STORING GOOGLE MAPS API KEY AS A VARIABLE

import googlemaps#Set Google MAPS API_Key
g_API = "API-Key Copied"
gmaps_key = googlemaps.Client(key=g_API)

STEP 2— LOOP OVER THE ADDRESSES AND GET THE GEOCODES

For our exercise, let us create fake addresses to use our codes:

from...

Continue reading: https://towardsdatascience.com/generating-geocodes-using-google-maps-api-eb56028821a6?source=rss—-7f60cf5620c9—4

Source: towardsdatascience.com