Python Google Map Introduction With Gmaps

Python Google Map Introduction With Gmaps – In this article we are going to talk about

creating Google Map in Python using Gmaps.

gmaps is a Jupyter plugin for embedding Google maps in Jupyter notebooks. It is designed to help

visualize and interact with geographical data.

 

 

 

Check more articles on Python Google Map

 

 

 

Installation Process

1: The easiest way to install gmaps is with conda:

$ conda install -c conda-forge gmaps

 

2: Installing jupyter-gmaps with pip

Make sure that you have enabled ipywidgets widgets extensions:

$ jupyter nbextension enable –py –sys-prefix widgetsnbextension

You can then install gmaps with:

$ pip install gmaps

Then tell Jupyter to load the extension with:

$ jupyter nbextension enable –py –sys-prefix gmaps

 

 

 

 

Authentication

Most operations on Google Maps require that you tell Google who you are. To authenticate with Google Maps, you need to go Google Cloud Console and create a new project and after that create your API Key from credentials.  The API key is a string that starts with the letters AI. Also after creation of API Key, you need to enable Maps Javascript API.

 

Python Google Map API Key
Python Google Map API Key

 

 

 

So now lets get started

 

gmaps is a plugin for Jupyter for embedding Google Maps in your notebooks. It is designed as a

data visualization tool. To demonstrate gmaps, let’s plot the earthquake dataset, included in the

package.

 

 

 

Run your jupyter notebook and add this code.

 

 

 

 

After run you will see this result.

Google Map Earthquake Data
Google Map Earthquake Data

 

 

The earthquake data has three columns: a latitude and longitude indicating the earthquake’s

epicentre and a weight denoting the magnitude of the earthquake at that point. Let’s plot the

earthquakes on a Google map:

 

 

 

This is the result

Python Google Map Introduction With Gmaps
Python Google Map Introduction With Gmaps

 

 

This gives you a fully-fledged Google map. You can zoom in and out, switch to satellite view and

even to street view if you really want. The heatmap adjusts as you zoom in and out.

 

 

gmaps is built around the idea of adding layers to a base map. After you’ve authenticated with

Google maps, you start by creating a figure, which contains a base map.

 

 

 

 

 

Run the code and this will be the result.

Python Google Map
Python Google Map

 

 

 

 

You then add layers on top of the base map, for instance, to add a heatmap layer.

 

 

 

 

And this will be the result

Python Satellite Google Map
Python Satellite Google Map

 

The locations array can either be a list of tuples, as in the example above, a numpy array of shape

$N times 2$ or a dataframe with two columns.Most attributes on the base map and the layers

can be set through named arguments in the constructor or as instance attributes once the

instance is created.

 

 

 

Base Maps

Your first action with gmaps will usually be to build a base map.

 

 

 

 

Run the code this will be the result

Google Map Center
Google Map Center

 

 

 

 

If you do not set the map zoom and center, the viewport will automatically focus on the data as you

add it to the map. Google maps offers three different base map types. Choose the base map type

by setting the map_type parameter.

 

 

 

 

Run the code this will be the result

Python Google Map Hybrid Map
Python Google Map Hybrid Map

 

 

 

 

 

Also this is another map type

 

 

 

 

Run the code and this is the result.

Terrain Map Type
Terrain Map Type

 

 

 

There are four map types available:

  • ‘ROADMAP’ is the default Google Maps style,
  • ‘SATELLITE’ is a simple satellite view,
  • ‘HYBRID’ is a satellite view with common features, such as roads and cities, overlaid,
  • ‘TERRAIN’ is a map that emphasizes terrain features.

 

 

 

 

 

Also you can watch the complete video for this article

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×