Visualizing Latitude and Longitude on Google Map Using Python
Visualizing geographic data on a map is a powerful way to gain insights and understand patterns in the data. One of the most popular platforms for creating interactive maps is Google Maps, which provides a rich set of tools for creating and customizing maps.
In this article you’ll learn about how to pin/drop/draw the latitude and longitude in google map using Python. To do this I’m going to use folium
python module.
folium
is a powerful Python library for creating interactive maps. It is built on the data visualization library leaflet.js
and allows you to easily create maps with markers, lines, and other features.
For this you need to install folium
Ubuntu: pip3 install folium
Windows: pip install folium
Now you need to import folium and create an object using folium.map(), that will generate a map.
# Here's an example of how you can use folium to create a simple map:
import folium
map = folium.Map(location=[21.39, 84.29], zoom_start=13)
This will create a map centered at the coordinates [21.39, 84.29]
, with a zoom level of 13. The location
parameter is a list of coordinates, while the zoom_start
parameter controls the initial zoom level of the map.
Now you need to plot some latitude and longitude on this Map. You can plot single as well as multiple points on the map, so now you can collect all latitude and Longitude as a list and store it into list (ex: list of lists).
points = [[20.5920749, 85.8017591], [20.5218388, 85.7341526], [21.3470154, 83.6320212]]
You can mark these above points using folium.Marker() and add it into the created map Object.
# for single point
folium.Marker(point, popup='My Home').add_to(map)
This will create a map with a marker at the coordinates [20.59, 85.80]
, and when you click on the marker it will display "My Home" in the pop-up.
# for multiple points
for point in points:
folium.Marker(point, popup='Point').add_to(map)
This will create a map with a marker at the all coordinates [[20.59, 85.80],[20.52, 85.73],[21.34,83.63]]
, and when you click on the marker it will display "Point" in the pop-up.
Now, our Google Map is ready with these points, to visualized it, you just need to call the created map object.
map
You Can also plot circle instead of pointing on the map
To plot circle on the map
for point in points:
folium.CircleMarker(point,radius = 5,color = 'red',fill = True).add_to(map)
You could also create different types of maps like Choropleth maps, Heat maps, Cluster map and many more . You can customize the appearance of the map by setting various options such as the starting zoom level, the map tiles, and the overall size of the map.folium
also allows you to import various data formats such as GeoJSON, TopoJSON, and WKT, which can be displayed on the map. You can also use the folium.plugins
module to add various types of interactivity to your maps.
Thanks for given you time here, please leave a clap if you like this article.