Python and Folium Map is a basic building block for Python and Folium map project.
- Clone the repository:
git clone https://github.com/gpalve/python-folium-map.git
- Install the required Python packages:
pip install -r requirements.txt
- Import the
folium
module:
import folium
- Create a
Map
object:
map = folium.Map(location=[37.7749, -122.4194], zoom_start=12)
- Add markers to the map:
folium.Marker(location=[37.7749, -122.4194], tooltip='San Francisco').add_to(map)
You can customize the marker icon and tooltip text by passing additional parameters to the Marker
method. For example, to use a custom icon:
icon_url = 'https://www.iconsdb.com/icons/preview/red/marker-2-xxl.png'
icon = folium.features.CustomIcon(icon_url, icon_size=(50, 50))
folium.Marker(location=[37.7749, -122.4194], tooltip='San Francisco', icon=icon).add_to(map)
To add a line between two points on the map:
points = [[37.7749, -122.4194], [37.3382, -121.8863]]
folium.PolyLine(points, color='red', weight=5, opacity=0.7).add_to(map)
You can also add other types of markers and shapes to the map, such as circles, polygons, and GeoJSON layers. Refer to the Folium documentation for more information.