Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Plotting Data on Google Map using Python's pygmaps package
Next article icon

Plotting Data on Google Map using Python's pygmaps package

Last Updated : 04 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

pygmaps

is a matplotlib-like interface to generate the HTML and javascript to render all the data users would like on top of Google Maps. Command to install

pygmaps

:

pip install pygmaps (on windows)
sudo pip3 install pygmaps (on linix / unix)

Code #1 :

To create a Base Map.

Python
# import required package import pygmaps  # maps method return map object # 1st argument is center latitude # 2nd argument is center longitude # 3ed argument zoom level mymap1 = pygmaps.maps(30.3164945, 78.03219179999999, 15)  # create the HTML file which includes # google map. Pass the absolute path # as an argument. mymap1.draw('pygmap1.html') 

Output:

Screenshot-882-copy-2


Code #2 :

To draw grids on map

Python
# importing pygmaps import pygmaps  mymap2 = pygmaps.maps(30.3164945, 78.03219179999999, 15)  # draw grids on the map # 1st argument is the starting point of latitude # 2nd argument is the ending point of latitude # 3rd argument is grid size in latitude # 4th argument is the starting point of longitude # 5th argument is the ending point of longitude # 6th argument is grid size in longitude mymap2.setgrids(30.31, 30.32, 0.001,                 78.04, 78.03, 0.001)                  mymap2.draw('pygmap2.html') 

Output:

Screenshot-881-copy-2


Code #3 :

To add a point into a map

Python
# importing pygmaps import pygmaps  # list of latitudes latitude_list = [30.3358376, 30.307977, 30.3216419,                  30.3427904, 30.378598, 30.3548185,                  30.3345816, 30.387299, 30.3272198,                  30.3840597, 30.4158, 30.340426,                  30.3984348, 30.3431313, 30.273471]  # list of longitudes longitude_list = [77.8701919, 78.048457, 78.0413095,                   77.886958, 77.825396, 77.8460573,                   78.0537813, 78.090614, 78.0355272,                   77.9311923, 77.9663, 77.952092,                   78.0747887, 77.9555512, 77.9997158]  mymap3 = pygmaps.maps(30.3164945, 78.03219179999999, 15)   for i in range(len(latitude_list)):      # add a point into a map     # 1st argument is latitude     # 2nd argument is longitude     # 3rd argument is colour of the point showed in thed map     # using HTML colour code e.g.     # red "# FF0000", Blue "# 0000FF", Green "# 00FF00"     mymap3.addpoint(latitude_list[i], longitude_list[i], "# FF0000")      mymap3.draw('pygmap3.html') 

Output:

pygmap3

Code #4 :

To Draw a circle of given radius

Python
import pygmaps  mymap4 = pygmaps.maps(30.3164945, 78.03219179999999, 15)  # Draw a circle of given radius # 1st argument is latitude # 2nd argument is longitude # 3rd argument is radius (in meter) # 4th argument is colour of the circle mymap4.addradpoint(30.307977, 78.048457, 95, "# FF0000") mymap4.draw('pygmap4.html') 

Output :

pygmap4

Code #5 :

To draw a line in b/w the given coordinates

Python
# Importing pygmaps import pygmaps  mymap5 = pygmaps.maps(30.3164945, 78.03219179999999, 15)  latitude_list =[30.343769, 30.307977] longitude_list =[77.999559, 78.048457]  for i in range(len(latitude_list)) :     mymap5.addpoint(latitude_list[i], longitude_list[i], "# FF0000")  # list of coordinates          path = [(30.343769, 77.999559),         (30.307977, 78.048457)]  # draw a line in b / w the given coordinates # 1st argument is list of coordinates # 2nd argument is colour of the line mymap5.addpath(path, "# 00FF00")  mymap5.draw('pygmap5.html') 

Output:

Screenshot-879-copy-2



Next Article
Plotting Data on Google Map using Python's pygmaps package

A

ankthon
Improve
Article Tags :
  • Python
  • python-utility
  • python-modules
Practice Tags :
  • python

Similar Reads

    Python | Plotting Google Map using gmplot package
    gmplot is a matplotlib-like interface to generate the HTML and javascript to render all the data user would like on top of Google Maps. Command to install gmplot : pip install gmplotCode #1 : To create a Base Map Python # import gmplot package import gmplot # GoogleMapPlotter return Map object # Pas
    2 min read
    Python | Plotting Google Map using folium package
    Folium is built on the data wrangling strengths of the Python ecosystem and the mapping strengths of the Leaflet.js (JavaScript) library. Simply, manipulate your data in Python, then visualize it on a leaflet map via Folium. Folium makes it easy to visualize data that's been manipulated in Python, o
    2 min read
    Python | Fetch Nearest Hospital locations using GoogleMaps API
    If you are ever curious about how you can fetch nearest places (restaurant, hospital, labs, cafe's, etc) location using your current location, this could be achieved using Python and Google Maps API. In this article, we will use Google Maps API to find the nearest hospital's locations using Python.
    2 min read
    Plotting World Map Using Pygal in Python
    Pygal is a Python module that is mainly used to build SVG (Scalar Vector Graphics) graphs and charts. SVG is a vector-based graphics in the XML format that can be edited in any editor. Pygal can create graphs with minimal lines of code that can be easy to understand and write.  We might want to plot
    3 min read
    Google Maps Selenium automation using Python
    Prerequisites: Browser Automation using Selenium Selenium is a powerful tool for controlling a web browser through the program. It is functional for all browsers, works on all major OS, and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python. It can
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences