Skip to content

Add basemap creation example with folium #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions python/basemap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# **Creating Interactive Maps with Folium**

This project demonstrates how to create interactive maps using the Python library **Folium**. Folium is a powerful tool for building maps with markers, popups, and other interactive features.

![Folium basemap](basemap-folium.jpg)

---

## **Requirements**

Ensure you have the following installed:

1. Python 3.7 or higher
2. pip (Python package manager)

---

## **Setup Instructions**

### 1. Clone the Repository

```bash
git clone https://github.com/geoapify/maps-api-code-samples.git
cd maps-api-code-samples/python
```

### 2. Create a Virtual Environment (Optional)

It’s recommended to use a virtual environment to avoid dependency conflicts:

```bash
python -m venv env
source env/bin/activate # On Windows: env\Scripts\activate
```

### 3. Install Folium

Install the Folium library using pip:

```bash
pip install folium
```

---

## **Running the Example**

Run the script to generate an interactive map:

```bash
python basemap-folium.py
```
This will create an HTML file named `folium_map.html`. Open it in your browser to view the map.

---
Binary file added python/basemap/basemap-folium.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions python/basemap/basemap-folium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import folium

# Variables for map configuration
location = [48.8584, 2.2945] # Latitude and Longitude of the Eiffel Tower
zoom_level = 15
marker_popup = "Eiffel Tower"
marker_color = "red"
output_file = "../../../geoapfiy-maps/pythonProject/folium_map.html"

# Create a Folium map centered on the location
map_folium = folium.Map(location=location, zoom_start=zoom_level)

# Add a marker at the specified location
folium.Marker(
location=location,
popup=marker_popup,
icon=folium.Icon(color=marker_color),
).add_to(map_folium)

# Save the map as an HTML file
map_folium.save(output_file)

print(f"Map created! Open {output_file} to view it.")