Skip to content

bigfunctions > geocode

geocode

Call or Deploy geocode ?

✅ You can call this geocode bigfunction directly from your Google Cloud Project (no install required).

  • This geocode function is deployed in bigfunctions GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error).
  • Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • You may prefer to deploy the BigFunction in your own project if you want 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). Discover the framework

Public BigFunctions Datasets:

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...

Description

Signature

geocode(address)

Description

Get address details from Google Maps

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"]
}
 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Need help using geocode?

The community can help! Engage the conversation on Slack

For professional suppport, don't hesitate to chat with us.

Found a bug using 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.

For professional suppport, don't hesitate to chat with us.

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.

Spread the word

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on