How to Create a Map with Longitude and Latitude in Python?

Estimated read time 2 min read

To create a map with longitude and latitude in Python, you can use the folium library. folium is a Python library that allows you to create interactive maps with various features, including markers, pop-ups, tooltips, and tiles. Here’s how you can create a basic map with markers at specified longitude and latitude coordinates:

import folium

# create a map object
m = folium.Map(location=[37.7749, -122.4194], zoom_start=12)

# add a marker
folium.Marker(location=[37.7749, -122.4194], popup='San Francisco').add_to(m)

# display the map
m

In this example, we first import the folium library. We then create a Map object with the folium.Map function, specifying the initial location and zoom level. The location parameter takes a list of two values: latitude and longitude. In this example, we use the coordinates of San Francisco.

We then add a marker to the map using the folium.Marker function, specifying the location of the marker and a popup message. In this example, we use the same coordinates as the initial location, and a popup message that says ‘San Francisco’.

Finally, we display the map by calling the Map object. The map will open in your browser as an interactive map.

You can add more markers to the map by calling the folium.Marker function with different coordinates and popup messages. You can also customize the appearance of the markers, the tiles, and the map controls using various parameters of the folium functions.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply