The Google Fusion Tables API will not be available after Dec. 3, 2019. Learn more

Sample code

An easy way to learn how to use an API is to look at sample code. The samples on this page demonstrate particularly interesting functionality in the Fusion Tables API or a variety of ways to access Fusion Table data.

Google Fusion Tables API v2.0

A quick way to try out the API is to type the command or query directly into your browser's toolbar. You can adjust the URL as you change your query or data needs and you'll get immediate feedback. See Getting Started. You can only do this with tables that are exportable and either public or unlisted, and you need to include your API key.

  • Lists all columns in a given table (try this):{your API key}
  • Runs a query to select all rows in a given table (try this): * FROM 1KxVV0wQXhxhMScSDuqr-0Ebf0YEt4m4xzVplKd4&key={your API key}
Function Description Language/API

Uses the API v2.0 to authenticate with OAuth and to manage styles and templates.

Hello, Python

  • OAuth 2.0 authentication.
  • Get, insert, update, delete styles.
  • Get, insert, update, delete templates.
Python, API v2.0

Uses dropdown menu selections of styles and templates to change a map display dynamically.

Styles and templates

  • Uses styleid and templateid.
  • Uses dropdown menu to change.
API v2.0

Uses mouseover events to dynamically change the style of a polygon region.

Mouseover map styles

  • Mouseover events.
  • Uses JSONP callback.
API v2.0

A simple JSONP callback implementation that lists all the data in a table.

Basic JSONP example

  • Simple list of table data.
  • Uses JSONP callback.
API v2.0

Visualization API

Using the Google Visualization API, you can request data from Fusion Tables to use in visualizations or to display directly in an HTML page. Note: responses are limited to 500 rows of data.

As a shortcut, you can use the Fusion Tables Chart Wizard to generate the code necessary to create charts from your Fusion Tables data.

Function Description (table) Language

Creates dynamic data tables with dropdown menu choices.

Basic request (2010 World Cup Goals)
Data varies for menu choices.
Data table visualization (2010 World Cup Goals)
Displays different data for different dropdown menu choices.

Creates bar charts

Bar chart visualization (Yearly coffee consumption)
You can click on a bar to find out coffee consumption by country and by year.

Drive SDK

With the Google Drive SDK, you can set table permissions and move tables into or out of a folder. For more information, see the Drive SDK documentation.

Function Description Language

Updates table permissions and do folder management.

Drive API example

Key points:

  • Lists tables.
  • Sets permissions on tables.
  • Moves a table to a folder.
Sets secure permissions for different collaborators of a view.

Collaborative data gathering

Key points:

  • Creates a view.
  • Sets permissions for the view.

Google Apps Script

These samples demonstrate the use of Google Apps Script to access Fusion Tables. Google Apps Script is a JavaScript cloud-scripting language that provides easy ways to automate tasks across Google products and third party services.

Function Description Language
Uses JavaScript-like Apps Script to list tables

Google Apps Script

Key points:

  • Uses client login.
  • Uses SHOW TABLES to list all the tables you own.
Google Apps Script
Sync Google Forms input with your table

Using forms with Fusion Tables

Key points:

  • Uses a simple script.
  • Allows form input.
  • Syncs data with table automatically.
Google Apps Script

Fusion Tables Layer — Google Maps JavaScript API

Using the Maps API FusionTablesLayer object, you can style polygons, lines, and map icons on a Google Map. As a shortcut, you can use the FusionTablesLayer Wizard to generate the code necessary to create one or more Fusion Table layers.

Note: These code samples use the Google Maps API and are therefore subject to the same usage limits and TOS as any other use of the Maps API.

Some code samples assume the use of our style sheet. Make sure you include it in your own versions of these samples.

Function Description (table) Language
Introduces the FusionTableLayer object.
Simple map layer (pizza stores)
Displays a map of pizza stores with a styled map layer that has a customized info window template and sets the marker location as the Address column. Another code sample is available here (Chicago homicides).
Multiple layers per map (county boundaries, hospitals)
Uses data from two tables to construct two map layers, each with its own info window template. It uses California county boundaries to display polygon shapes behind another layer that displays markers at hospital locations.
Using checkbox to show heatmap (Brazil beaches)
Displays a checkbox to show a heatmap of the many beaches in Brazil.
Zoom in (single location)
As users zoom in, the region's shape is more precise.

Allows users to choose which pizza stores to display:

  • Using a dropdown menu.
  • Using checkboxes.
  • Using autocomplete text in a search box.
Dropdown menu (pizza stores)
Constructs a query depending on dropdown menu choice and displays all or only some stores.
Checkboxes (pizza stores)
Constructs a query depending on checkbox choices and displays all or only some stores.
Autocomplete Textbox (pizza stores)
Uses text input autocomplete to construct query.

Maps API: FusionTablesLayer — finding, styling, customizing

Function Description (table) Language
Spatial queries: Finds map features within a defined area. See Working with geographic data.
Features within a radius (pizza stores)
Uses ST_INTERSECTS within a defined circle area.
Features within a bounding box (pizza stores)
Uses ST_INTERSECTS within a defined rectangular area.
"Nearest neighbor" features (pizza stores)
Uses ORDER BY ST_DISTANCE and LIMIT 3 to display the three closest stores to a specific point.
Customizes styles in a map layer, even include different legend boxes.
Basic styling (Australian eco regions)
Depending on data values, displays regional polygons in different colors.
Dynamic map styles with two legends (urban and rural housing units)
Depending on dropdown menu choice, displays different legends and different map styles.
Legend (US Butterflies)
Different marker and legend colors for each species.
Customizes info window templates
Dynamic templates (pizza stores)
Depending on data values, displays different info window templates.
Template with driving directions (locations)
Info window allows text input, then displays route on map layer.
Open template at user-entered address (pizza stores)
Parses entered address, geocodes it, and checks its delivery zone.

Advanced Fusion Tables Layer — Google Maps JavaScript API

Function Description (table) Language

Displays chart + map:

  • Uses two visualizations.
  • Pans and zooms to locations.
Chart plus map (population history)
Displays a chart for a state when you click that state's marker on the map.
Custom marker icons (pizza stores)
Uses the Visualization API and parses the KML coordinates of delivery areas.
Pan and zoom (Google locations)
Finds user's location and zooms in.

Uses different APIs and many map attributes:

  • FusionTablesLayer objects.
  • Visualization API.
  • Multiple dropdown menus.
  • Dynamic styles.
  • Dynamic charts.
  • Dynamic legend.
  • Custom info windows.
  • Data from three merged data tables combined.
Advanced sample code (electricity consumption by county)
Uses a three-way merge table to display a complex chart plus dynamic styles and legends.

As users change dropdown selections or click on counties, the map and chart elements change. The info window contents vary for different data values.

Tools and interfaces from Fusion Tables developers

Several Fusion Tables developers have created useful tools and interfaces for use with Fusion Tables.