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, on an interactive Leaflet map. This library has a number of built-in tilesets from OpenStreetMap, Mapbox etc.

Command to install folium module :

pip install folium==0.1.5

Code #1 : To create a Base Map.



filter_none

edit
close

play_arrow

link
brightness_4
code

# import folium package
import folium
  
# Map method of folium return Map object
  
# Here we pass coordinates of Gfg 
# and starting Zoom level = 12
my_map1 = folium.Map(location = [28.5011226, 77.4099794],
                                        zoom_start = 12 )
  
# save method of Map object will create a map
my_map1.save(" my_map1.html " )

chevron_right


Output :

 
Code #2 : Add a circular marker with popup text.

filter_none

edit
close

play_arrow

link
brightness_4
code

# import folium package
import folium
  
my_map2 = folium.Map(location = [28.5011226, 77.4099794],
                                         zoom_start = 12)
  
# CircleMarker with radius
folium.CircleMarker(location = [28.5011226, 77.4099794],
                    radius = 50, popup = ' FRI ').add_to(my_map2)
  
# save as html
my_map2.save(" my_map2.html ")

chevron_right


Output :

 
Code #3 : Add a simple_marker for parachute style marker with pop-up text.

filter_none

edit
close

play_arrow

link
brightness_4
code

# import folium package
import folium
  
my_map3 = folium.Map(location = [28.5011226, 77.4099794],
                                        zoom_start = 15)
  
# Pass a string in popup parameter
folium.Marker([28.5011226, 77.4099794],
               popup = ' Geeksforgeeks.org ').add_to(my_map3)
  
  
my_map3.save(" my_map3.html ")

chevron_right


Output :

 
Code #4 : Add a line to the map

filter_none

edit
close

play_arrow

link
brightness_4
code

# import folium package
import folium
  
my_map4 = folium.Map(location = [28.5011226, 77.4099794],
                                        zoom_start = 12)
  
folium.Marker([28.704059, 77.102490],
              popup = 'Delhi').add_to(my_map4)
  
folium.Marker([28.5011226, 77.4099794],
              popup = 'GeeksforGeeks').add_to(my_map4)
  
# Add a line to the map by using line method .
# it connect both coordiates by the line
# line_opacity implies intensity of the line
  
folium.PolyLine(locations = [(28.704059, 77.102490), (28.5011226, 77.4099794)],
                line_opacity = 0.5).add_to(my_map4)
  
my_map4.save("my_map4.html")

chevron_right


Output :



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.