Skip to content

geocode

geocode(address)

Description

Get address details from Google Maps

Usage

Call or Deploy geocode ?
Call geocode directly

The easiest way to use bigfunctions

  • geocode function is deployed in 39 public datasets for all of the 39 BigQuery regions.
  • It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)

Public BigFunctions Datasets

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...
Deploy geocode in your project

Why deploy?

  • You may prefer to deploy geocode in your own project to build and manage your own catalog of functions.
  • This is particularly useful if you want to create private functions (for example calling your internal APIs).
  • Get started by reading the framework page

Deployment

geocode function can be deployed with:

pip install bigfunctions
bigfun get geocode
bigfun deploy geocode

Requirements

geocode uses the following secrets. Get them by reading the documentation link and store them in Google Secret Manager in the project where you deploy the function (and give Accessor role to the service account of the function):

name description documentation to get the secret
gmaps_api_key Google Maps Api Key doc

Examples

select bigfunctions.eu.geocode("1 rue des champs elysees, Paris")
select bigfunctions.us.geocode("1 rue des champs elysees, Paris")
select bigfunctions.europe_west1.geocode("1 rue des champs elysees, Paris")
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| address_details                                                                                                                                                                                                                                                                                                                                                 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {
    "address_components": [...],
    "formatted_address": "1 Av. des Champs-Élysées, 75008 Paris, France",
    "geometry": {
        "location": {
            "lat": 48.86988770000001,
            "lng": 2.3079341
        },
        ...
    },
    "place_id": "ChIJ6499V8Rv5kcR5f9dbz3OeBI",
    "plus_code": {...},
    "types": ["street_address"]
}
 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Use cases

A use case for the geocode function is to enrich a dataset of customer addresses with geographic information.

Scenario: An e-commerce company has a table of customer data, including their addresses as text strings. They want to analyze sales by geographic region, calculate shipping distances, or visualize customer locations on a map.

Implementation:

  1. Data: The company has a BigQuery table named customers with columns like customer_id, address, etc.

  2. Geocoding: They use the geocode function to get the latitude, longitude, and other location details for each customer address.

SELECT
    customer_id,
    address,
    bigfunctions.us.geocode(address).geometry.location.lat AS latitude,
    bigfunctions.us.geocode(address).geometry.location.lng AS longitude,
    bigfunctions.us.geocode(address).formatted_address AS standardized_address
FROM
    `customers`;
(Remember to replace bigfunctions.us with the appropriate dataset for your region.)

  1. Enriched Data: The query above creates a new table (or you can save the results into a new column in the existing table) with the original customer data plus the derived latitude, longitude, and standardized_address. The standardized_address is helpful for data cleaning and consistency.

  2. Downstream Analysis: Now the company can use the latitude and longitude information for various analytical purposes:

    • Sales Analysis by Region: Aggregate sales data based on customer location (e.g., total sales within a specific city or state).
    • Shipping Optimization: Calculate distances between warehouses and customer locations to optimize delivery routes and estimate shipping costs.
    • Customer Segmentation: Group customers based on proximity for targeted marketing campaigns.
    • Data Visualization: Visualize customer locations on a map to identify geographic patterns and trends.

Benefits:

  • Improved Data Accuracy: Geocoding standardizes addresses and provides accurate location data, which is crucial for accurate analysis.
  • Enhanced Business Insights: Geographic data enables deeper analysis of customer behavior and market trends.
  • Operational Efficiency: Optimized shipping routes and targeted marketing campaigns lead to cost savings and increased revenue.

This example illustrates a common use case for geocoding in business analytics. By leveraging the geocode function, companies can enrich their data with valuable location information and unlock new possibilities for analysis and decision-making.


Need help or Found a bug?
Get help using geocode

The community can help! Engage the conversation on Slack

We also provide professional suppport.

Report a bug about geocode

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

We also provide professional suppport.


Show your ❤ by adding a ⭐ on