To plot a Google Map using the Folium package in Python, you first need to install the package by running the command pip install folium
in your command prompt or terminal.
Then, you can follow the steps below:
- Import the necessary libraries:
import folium from folium.plugins import HeatMap
- Create a map object:
m = folium.Map(location=[latitude, longitude], zoom_start=13)
Here, latitude
and longitude
represent the coordinates of the location you want to plot, and zoom_start
determines the initial zoom level of the map.
- Add a marker to the map:
folium.Marker( location=[latitude, longitude], popup='Your Popup Text Here', icon=folium.Icon(color='blue', icon='cloud') ).add_to(m)
Here, popup
is the text that appears when the marker is clicked, and icon
is the icon that appears at the marker’s location.
- Save the map as an HTML file:
m.save('map.html')
Alternatively, you can also plot a heatmap on the map using the HeatMap
plugin. Here’s how you can do it:
- Import the necessary libraries:
import folium from folium.plugins import HeatMap
- Create a map object:
m = folium.Map(location=[latitude, longitude], zoom_start=13)
Here, latitude
and longitude
represent the coordinates of the location you want to plot, and zoom_start
determines the initial zoom level of the map.
- Create a list of coordinates:
locations = [[latitude1, longitude1], [latitude2, longitude2], ...]
Here, latitude1
, longitude1
, latitude2
, longitude2
, etc. represent the coordinates of the points you want to include in the heatmap.
- Create the heatmap layer:
HeatMap(locations).add_to(m)
- Save the map as an HTML file:
m.save('map.html')
This will generate an HTML file with the plotted Google Map. You can open the file in a web browser to view the map.
Conclusion:
In conclusion, plotting a Google Map using the Folium package in Python is a straightforward process. You can create a map object, add a marker, and save the map as an HTML file. You can also plot a heatmap on the map using the HeatMap plugin. This can be useful for visualizing geographic data and making informed decisions based on the insights gained from the plotted data.