How to add the marker to the folium map in Python

In this tutorial, we will learn how to visualize data and add markers to the folium map in Python.

What is Folium?

Folium is a Python library. It helps us to visualize geospatial data involving information about longitude and latitude. It is helpful when we want to visualize data regarding poverty, the economy, the environment, etc.

How to install folium?

We can install the folium library using the following pip command.

pip install folium

This will install the Python library in our system.

Create  Visualization with folium

import folium
Delhimap = folium.Map(location=(28.612894, 77.229446) , zoom_start=10)
Delhimap

In the above code, the first value in the parameter is folium.map function indicates Latitude and the second value indicates Longitude. The zoom parameter is important because it will show the map with the initial zoom value. It will decide how the map will appear when we visualize it first.

Output:

Create  Visualization with folium

The above map shows New Delhi on the map without a marker.

How to add a marker to the map

What is a marker?

To understand the map easily and make the map more interpretable we can add markers. It is a symbol that gives extra information about the place in consideration. It gives additional knowledge about the place.

Delhimap = folium.Map(location=(28.612894, 77.229446), zoom_start=10)
folium.Marker( location=[28.612894, 77.229446],tooltip="I am a marker",popup="This is New Delhi",icon=folium.Icon(icon="cloud",color="green")).add_to(Delhimap)
Delhimap

In the given code folium.marker object we are using to add a marker. Under this object, there are different parameters. The location parameter is used to indicate the location of New Delhi. Which is taking latitude and longitude as input values. Tooltip parameter showing value when we click on the marker. The add function at the end is adding these marker values to the map.

Output:

folium marker tooltip

The above map shows New Delhi on the map with a marker.

To learn how to add color to folium marker please refer the following link

Set folium map marker color based on a value in Python

Leave a Reply

Your email address will not be published. Required fields are marked *