Formula Generator | Excel

Calculate Driving Time in Excel Using Google Maps API

Learn how to calculate driving time between two locations in Excel using the WEBSERVICE and FILTERXML functions with the Google Maps Distance Matrix API for real-time travel data.


Empty image or helper icon

Prompt

calculate driving time bettwin two places

Answer

Excel Formula for Calculating Driving Time Between Two Places

To calculate driving time between two locations in Excel, we can utilize the WEBSERVICE and FILTERXML functions, which allow us to fetch and parse data from a web service that provides travel time based on geographical coordinates or addresses.

Formula

The formula to calculate driving time using the Google Maps Distance Matrix API is structured as follows:

=FILTERXML(WEBSERVICE("https://maps.googleapis.com/maps/api/distancematrix/xml?origins=" & A1 & "&destinations=" & B1 & "&key=YOUR_API_KEY"), "//duration/text()")

Explanation of Components

  • WEBSERVICE: Fetches data from the specified URL. In this case, it's the Google Maps Distance Matrix API.
  • URL:
    • origins= specifies the starting location (cell A1).
    • destinations= specifies the ending location (cell B1).
    • key= is required for authentication; replace YOUR_API_KEY with your actual Google Maps API key.
  • FILTERXML: Parses the XML response from the web service to extract specific data. The XPath //duration/text() retrieves the driving time from the returned data.

Prerequisites

  1. API Key: You need a Google Maps API key. This requires creating a project in Google Cloud and enabling the Distance Matrix API.
  2. Availability: The WEBSERVICE and FILTERXML functions are available in Excel 2013 and later, but the API call requires an internet connection.

Practical Example

  1. In cell A1, enter the origin address (e.g., "1600 Amphitheatre Parkway, Mountain View, CA").
  2. In cell B1, enter the destination address (e.g., "1 Infinite Loop, Cupertino, CA").
  3. In cell C1, enter the formula:
=FILTERXML(WEBSERVICE("https://maps.googleapis.com/maps/api/distancematrix/xml?origins=" & A1 & "&destinations=" & B1 & "&key=YOUR_API_KEY"), "//duration/text()")
  1. Replace YOUR_API_KEY with your actual Google Maps API key.

Output

The output in cell C1 will display the estimated driving time between the two specified locations in a format such as "1 hour 15 mins".

Conclusion

This approach allows users to calculate driving time seamlessly in Excel using real-time data from the Google Maps API. By entering corresponding addresses and applying the above formula, one can obtain accurate travel times suitable for various analysis purposes in data-driven projects.

For further enhancement of skills in similar data analysis topics, consider exploring methodologies and resources available in the Enterprise DNA Platform.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

Learn how to calculate driving time between two locations in Excel using the WEBSERVICE and FILTERXML functions with the Google Maps Distance Matrix API for real-time travel data.