Lecture 3.1.3
Lecture 3.1.3
ENGINEERING
COMPUTER SCIENCE ENGINEERING
Data Visualization
(CSH-461)
The Google Maps API is a robust platform that provides a variety of tools to integrate
geographical data visualization into applications. It supports interactive maps, geocoding,
directions, and more.
2. Setting Up and Using the Google Maps API for Geographical Data in Python
Step 1: Getting an API Key To use the Google Maps API, you'll need an API key. Here's
how to obtain one:
1.Visit the Google Cloud Console.
2.Create a new project or select an existing project.
3.Navigate to "APIs & Services" > "Credentials".
4.Click on "Create Credentials" > "API Key".
5.Copy the generated API key for use in your application.
Step 2: Installing Required Libraries You will need the gmplot library to plot
geographical data on Google Maps using Python. Install it using pip:
Step 3: Initializing the Map Here's how you can create a basic map centered at a
specific location:
import gmplot
api_key = 'YOUR_API_KEY'
gmap = gmplot.GoogleMapPlotter(37.7749, -122.4194, 13, apikey=api_key)
gmap.draw("map.html") 4
3. Plotting Data on Maps and Customizing Visualizations
Plotting Markers: To add markers to your map, you can use the marker method:
gmap.marker(37.7749, -122.4194, title="San Francisco")
gmap.draw("map_with_marker.html")
4. Plotting Multiple Locations: You can plot multiple locations using the scatter method:
latitude_list = [37.7749, 37.7849, 37.7949]
longitude_list = [-122.4194, -122.4294, -122.4394]
gmap.scatter(latitude_list, longitude_list, color='red', size=40, marker=True)
gmap.draw("map_with_scatter.html")
5
5. Drawing Polygons: You can draw polygons to highlight areas on the map:
latitude_polygon = [37.7749, 37.7849, 37.7949]
longitude_polygon = [-122.4194, -122.4294, -122.4394]
gmap.draw("map_with_polygon.html")
6. Adding Heatmaps: Heatmaps are useful for visualizing the intensity of data points:
latitude_heatmap = [37.7749, 37.7849, 37.7949]
longitude_heatmap = [-122.4194, -122.4294, -122.4394]
gmap.heatmap(latitude_heatmap, longitude_heatmap)
gmap.draw("map_with_heatmap.html")
6
THANK YOU
For queries
Email: [email protected]