Visualizing Location on Google Map Using Python

NIKHIL AGARWAL
2 min readJul 29, 2023

--

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 👇👨🏻‍💻

import geopy 
object=geopy.Nominatim(user_agent="Nikki")
location = input("Enter the location ")
h=object.geocode(ation)
import folium
map = folium.Map(location=[h.latitude,h.longitude], zoom_start=13)
folium.Marker([h.latitude,h.longitude], popup='My Home').add_to(map)
map

Output

Explaining of all the code: 👇

Certainly! Let’s go through the main lines of the code step by step and explain what they do:

  1. import geopy: it is possible using geopy to extract the coordinates meaning its latitude and longitude.
  2. 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.
  3. location = input(“Enter the location “): input() takes the input give back to variable
  4. 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
  5. import folium: it is possible using folium to generate a map.
  6. 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.
  7. 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.
  8. 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

--

--

NIKHIL AGARWAL

STUDENT AT Swami Keshvanand Institute of Technology, Management & Gramothan, Jaipur