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 location in google map using Python. To do this I’m going to use folium and geopy python module.
Here below Integrate GPS co-ordinate with Pythonthe following code which you all can see 👇👨🏻💻
location = input("Enter the location ")
map = folium.Map(location=[h.latitude,h.longitude], zoom_start=13)
folium.Marker([h.latitude,h.longitude], popup='My Home').add_to(map)
Explaining of all the code: 👇
Certainly! Let’s go through the main lines of the code step by step and explain what they do:
- import geopy: it is possible using geopy to extract the coordinates meaning its latitude and longitude.
- object=geopy.Nominatim(user_agent=”Nikki”):On calling the Nomination tool which accepts an argument of user_agent you can give any name as it considers it to be the name of the app to which it is providing its services.
- location = input(“Enter the location “): input() takes the input give back to variable
- h=object.geocode(location):The geocode() function accepts the location name and returns a geodataframe that has all the details and since it’s a dataframe we can get the address, latitude and longitude by simply calling it with the given syntax
- import folium: it is possible using folium to generate a map.
- map = folium.Map(location=[h.latitude,h.longitude], zoom_start=13):This will create a map centered at the coordinates , 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.
- folium.Marker([h.latitude,h.longitude], popup=’My Home’).add_to(map): This will create a map with a marker at the coordinates , and when you click on the marker it will display "My Home" in the pop-up.
- map : To show the map
When you run this code , map display about location mentioned by the user. here we are using jupyter notebook for running the process