Plotting ICMR approved test centers on Google Maps using folium package
Last Updated :
22 Jun, 2020
Folium is a powerful data visualization library in Python that was built primarily to help people visualize geospatial data. With Folium, a map of any location in the world can be created as long as its latitude and longitude values are known. Also, the maps created by Folium are interactive in nature, so that you can zoom in and out after the map is rendered, which is a very useful feature. Folium builds on the Python ecosystem’s data wrangling powers and the Leaflet.js library’s mapping powers. In Python, the data is manipulated and then visualized via folium on a Leaflet map.
Installation
Before you can use Folium, you may need to install it on the system using either of the two methods below.
$ pip install folium
or
$ conda install -c conda-forge folium
We’ll be working with the ICMR dataset which has 7 columns: lab, address, Pincode, city, state, type, latitude, and longitude. We will be using the ‘ICMRTestingLabsWithCoords.csv’ file in the dataset. To download the dataset click here.
Getting Started
Importing required libraries
import folium
import pandas as pd
Importing dataset
df = pd.DataFrame(pd.read_csv(‘ICMRTestingLabsWithCoords.csv’))
For focusing the window only on India. We pass India’s coordinates along with zoom Parmenter to folium.Map().
phone_map = folium.Map(location = [20.5937, 78.9629],
zoom_start=4.4)
Making the Marker
To display name and type of laboratory whether it is private or government-based. Also, to pass the coordinates of the markers, we will be writing a Python code for it.
locate = {}
for i, j, k, l in zip(df['latitude'],
df['longitude'],
df['lab'],
df['type']):
temp=[]
temp.extend((i, j))
locate['loc']=temp
marker = folium.Marker(location = locate['loc'],
popup = str(k)+' Type:'+str(l))
marker.add_to(phone_map)
We will be running a for loop through 4 columns ‘latitude’, ‘longitude’, ‘lab and ‘type’. First, we create a ‘temp’ list which holds latitude and longitude of the particular labs as we traverse through all. This particular latitude and longitude list are then passed to a dictionary locate. Now we create a marker by calling ‘.Marker ‘ from the folium and passing in the locate dictionary to location and popup takes lab name and type of lab in string format. The type of marker is ‘folium.map.Marker’. Finally we call ‘.add_to’ off of the marker and passing in the phone_map. Now that our pins are ready it’s time to display the plotted pins. We do that by calling phone_map.
phone_map
Full Code:
Python3
import folium
import pandas as pd
phone_map = folium.Map(location=[20.5937, 78.9629],
zoom_start=4.4)
df = pd.DataFrame(pd.read_csv('ICMRTestingLabsWithCoords.csv'))
locate = {}
for i, j, k, l in zip(df['latitude'], df['longitude'],
df['lab'], df['type']):
temp = []
temp.extend((i, j))
locate['loc'] = temp
marker = folium.Marker(location=locate['loc'],
popup=str(k)+' Type:'+str(l))
marker.add_to(phone_map)
phone_map
Output:
Similar Reads
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
Outline specific area on Google Map using GeoJson
Folium builds on the data wrangling strengths of the Python ecosystem and the mapping strengths of the leaflet.js library. Manipulate your data in Python, then visualize it in on a Leaflet map via folium. It supports Image, Video, GeoJSON, and TopoJSON overlays. Installation: To install this module
2 min read
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
Plotting Data on Google Map using Python's pygmaps package
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 p
3 min read
Create a Map with Google Map Api using React-Native
In this project, we'll explore how to integrate Google Maps into a React Native application. We'll create a dynamic map that allows users to view their current location and interact with markers on the map. This project aims to provide a practical guide for developers looking to incorporate maps int
3 min read
How to create a Location finder app using ReactJS ?
In this article, we will be building a location finder app that lets you search for different places on a map. Our app contains two sections, one for displaying the marker on the map and the other is for searching different places. For rendering the map and getting the coordinates for the searched l
4 min read
3D Plotting sample Data from MongoDB Atlas Using Python
MongoDB, the most popular NoSQL database, is an open-source document-oriented database. The term âNoSQLâ means ânon-relationalâ. It means that MongoDB isnât based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data. This fo
3 min read
Visualizing Geospatial Data using Folium in Python
One of the most important tasks for someone working on datasets with countries, cities, etc. is to understand the relationships between their data's physical location and their geographical context. Â And one such way to visualize the data is using Folium. Folium is a powerful data visualization libr
3 min read
Python | Geographical plotting using plotly
Geographical plotting is used for world map as well as states under a country. Mainly used by data analysts to check the agriculture exports or to visualize such data. plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like
2 min read
Stamen Toner ,Stamen Terrain and Mapbox Bright Maps in Python-Folium
Folium library is a powerful data visualization library in Python used by people to visualize geospatial data and maps. With the Folium library, we can create map of any location in the world with the help of latitude and longitude of that location. We can also create interesting visualizations by s
3 min read