Post

Python Leaflet Map With Folium

Leaflet is a powerful Javascript library for interactive maps. I’ve wanted to have a go at using Leaflet for a while, but learning Javascript for just one library seemed over the top. Thankfully I’ve recently found Folium - a python package that makes it easy to produce a Python Leaflet map.

A Simple Python Leaflet Map

Here’s a simple example of the kind of map that is possible in Leaflet (taken from a post of mine). This example has a base layer of an OpenStreetMap map centred on Colchester in the UK. Overlaid on the map are some markers, which when you click on them reveal a label indicating the location of the marker (in this case public toilets).

Find out more about this map, and download the python code here.

How to Install Folium

For a full install guide visit the Folium docs, but to get you going you can just run

1
pip install folium

Creating a map is then simple:

1
2
3
import folium
map_osm = folium.Map(location=[45.5236, -122.6750])
map_osm.save('london.html')

which saves a map that looks a bit like this:

Visit the Folium Getting Started guide for more tips to get you going.

Folium Features

Visit the Folium pypi page for more about its features. You can also find a features library filled with examples here and here. Folium is still very much under development, so also check out the project’s github page for more updates and information.

This post is licensed under CC BY 4.0 by the author.