Use Google Maps API to Visualize BigQuery Geospatial Data




Enable the Maps Javascript API and generate an API key

Create OAuth 2.0 Credentials

Implement BigQuery API functions

Add circles functionality

Use Google Maps API to Visualize BigQuery Geospatial Data

1 jam 30 menit 7 Kredit


Google Cloud Self-Paced Labs


In this lab you will use the Google Maps Platform to visualize taxi drop off locations in 2016 from journeys that started from the block around the Empire State building. This data is stored in a Google BigQuery public dataset.

You will slowly build up the necessary code until you can draw an area (either a rectangle or a circle) that has the heatmap of the drop off data displayed. The location data is fetched from BigQuery using a different method based on the type of query. Each query will use the BigQuery GIS functions.

Main Image

  • Rectangle queries: specify the rectangle using ST_MAKEPOLYGON with ST_GEOPOINT to make the rectangle and then test if the point is within using ST_CONTAINS.
  • Radius queries: specify if the point is within the radius using BigQuery GIS functions ST_DISTANCE and ST_GEOPOINT.

Standard SQL vs. Legacy SQL

BigQuery supports two versions of SQL: Legacy SQL and Standard SQL. The latter is the 2011 ANSI standard. Standard SQL is used in this lab because it has better standards compliance and it's required for the GIS functions.

Rectangle Queries

Rectangle queries are straightforward to construct in BigQuery. You create a polygon using the points of the rectangle and then use ST_CONTAINS to decide if you include it in the matches.

Radius Queries

Radius queries are easy to construct, since you know the circle center and the radius. You use ST_DISTANCE to find the difference of the pickup point and the circle center, and check that it's inside the radius to decide if it should be included in the matches.


You have now reviewed two types of spatial query using BigQuery. As you have seen, location makes a big difference to the result data for the queries against this dataset, but unless you guess where to run your queries, it is hard to discover spatial patterns ad-hoc using just SQL queries.

If only you could visualise the data on a map, and explore the data by defining arbitrary areas of interest! Using the Google Maps APIs you can do just that. You will enable the Maps API, set up a simple web page, and start using the BigQuery API to send queries from your web page.

Lab Objectives

Learning Objective
1 How to query petabyte-scale location datasets in seconds with BigQuery, using SQL queries, User Defined Functions and the BigQuery API
2 How to use the Google Maps Platform to add a Google Map to a web page and enable users to draw shapes on it
3 How to visualize queries against large datasets on a Google Map like in the example image below, which shows the density of taxi drop off locations in 2016 from journeys that started from the block around the Empire State Building

Bergabunglah dengan Qwiklabs untuk membaca tentang lab ini selengkapnya... beserta informasi lainnya!

  • Dapatkan akses sementara ke Google Cloud Console.
  • Lebih dari 200 lab mulai dari tingkat pemula hingga lanjutan.
  • Berdurasi singkat, jadi Anda dapat belajar dengan santai.
Bergabung untuk Memulai Lab Ini