Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Views: 12
Image: ubuntu2204
Kernel: Python 3 (system-wide)

Installing ipyleaflet

Ensure you have ipyleaflet installed. Since we cannot assume existing setups, here we provide the installation command:

Importing necessary libraries

Import the Map and Marker classes from ipyleaflet:

from ipyleaflet import Map, Marker

Understanding ipyleaflet

ipyleaflet is a Jupyter interactive widget library, providing an interactive map for data visualization in notebooks. It is built on top of leaflet.js, a popular JavaScript library for mobile-friendly interactive maps.

Creating a map centered on California State University, Fresno

Initialize an interactive map. California State University, Fresno is located at latitude 36.8121 and longitude -119.7475:

center = (36.8121, -119.7475) m = Map(center=center, zoom=15) m

Adding a marker

To mark the location of California State University, Fresno, create a Marker and add it to the map:

marker = Marker(location=center, draggable=False) m.add_layer(marker)

Displaying the map

The final step is to display the map in a Jupyter notebook cell:

By running the cell containing the map object, you'll see the interactive map below:

m # This will display the map in the notebook

This setup displays an interactive map centered on the location of California State University, Fresno with a marker indicating the campus location. The map allows you to pan and zoom, providing a hands-on exploration experience. Adjust the center and zoom for different locations and viewing preferences.