Python | Plotting Data on Google Map using pygmaps package
pygmaps 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 pygmaps :
pip install pygmaps (on windows) sudo pip3 install pygmaps (on linix / unix)
Code #1 : To create a Base Map.
# 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 include # google map. Pass the absolute path # as an argument. mymap1.draw('pygmap1.html') |
Output:

Code #2 : To draw grids on map
# importing pygmaps import pygmaps mymap2 = pygmaps.maps(30.3164945, 78.03219179999999, 15) # draw grids on map # 1st argument is starting point of latitude # 2nd argument is ending point of latitude # 3rd argument is grid size in latitude # 4th argument is starting point of longitude # 5th argument is 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:

Code #3 : To add a point into a map
# 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:

Code #4 : To Draw a circle of given radius
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 :

Code #5 : To draw a line in b/w the given coordinates
# 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:

Recommended Posts:
- Python | Plotting Google Map using folium package
- Python | Plotting Google Map using gmplot package
- Python | Plotting charts in excel sheet with data tools using XlsxWriter module | Set – 2
- Python | Plotting charts in excel sheet with Data Tools using XlsxWriter module | Set - 1
- Python | Plotting column charts in excel sheet with data tables using XlsxWriter module
- Create and Access a Python Package
- Graph Plotting in Python | Set 3
- Graph Plotting in Python | Set 1
- Graph Plotting in Python | Set 2
- Python | Geographical plotting using plotly
- Plotting graph using Seaborn | Python
- Python | Adding markers to volcano locations using folium package
- NetworkX : Python software package for study of complex networks
- SunPy | Plotting a Solar Image in Python
- Python | Matplotlib Sub plotting using object oriented API
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



