Predicting future travel times with the Google Maps APIs

Elena kelareva.

Product Manager, Google Maps APIs

  • If your application is used for scheduling deliveries, and you want to ensure you’ve allowed enough time between deliveries so your drivers won’t be late, you might want to use the pessimistic travel time estimates.
  • On the other hand, if you’re building a thermostat app, and you want the house to be warm by the time your user arrives home from work, you might want to use the optimistic travel time estimate to calculate when the user is likely to arrive.
  • If you want to give your user an estimate of the most likely travel time to their destination, the default best_guess traffic model will give you the most likely travel time considering both current traffic conditions and historical averages.

https://storage.googleapis.com/gweb-cloudblog-publish/images/Predictive_Maps.max-700x700.png

“Taking the guesswork out of knowing how long it will take to drive between homes will help us provide a better customer experience to our users” – Curtis Howell, Product Manager Customer Engagement, Redfin

  • Inside Google Cloud

Related articles

https://storage.googleapis.com/gweb-cloudblog-publish/images/whats_new.max-700x700.jpg

What’s new with Google Cloud

By Google Cloud Content & Editorial • 3-minute read

What’s new with Google Cloud - 2023

By Google Cloud Content & Editorial • 29-minute read

https://storage.googleapis.com/gweb-cloudblog-publish/images/Google_Cloud_AIML_thumbnail.max-700x700.jpg

Shared fate: Protecting customers with generative AI indemnification

By Neal Suggs • 4-minute read

https://storage.googleapis.com/gweb-cloudblog-publish/images/People-of-GC_Jack_Ngare.max-700x700.jpg

“The time is now.” Why this Kenyan Googler is betting on Africa’s tech opportunity

  • Google Maps Platform
  • Español – América Latina
  • Português – Brasil
  • Tiếng Việt
  • Web Services
  • Documentation

Routes API Overview

google maps api estimated travel time

Why use the Routes API

With the Routes API, you can get accurate routes and trip information using transport details, up-to-date traffic and road conditions, and route preferences:

Type and capabilities of different modes of transport

Which direction a vehicle is headed

The side of the road for pick ups or drop offs

Traffic conditions and road closures

Safety concerns such as avoiding dangerous areas or providing safe pickup areas

Balance latency, quality, and cost across your routing needs with optional features such as tolls and trip metadata such as time and distance, and fuel efficiency

You can also determine the most efficient routes for dispatch scheduling, such as:

How best to assign a set of workers to pick up a series of packages

Determine the best warehouse from which to ship packages to their final destination

What you can do with the Routes API?

With the Routes API, you can get two primary categories of routing information:

Routes from a location to a single or multiple destinations

A matrix of possible routes between many start and end locations.

Get routes for single or multiple destinations

With the Routes API Compute Routes method, you can calculate between locations:

Get directions for different ways to travel , and for a single or multiple destinations:

Modes of transportation, including transit, driving, two-wheel vehicles, walking or bicycling.

A series of waypoints, that you can optimize for the most efficient order to travel them in.

Multiple ways to specify origins, destinations, and waypoints :

Text strings. For example: "Chicago, IL", "Darwin, NT, Australia", "1800 Amphitheatre Parkway, Mountain View, CA 94043", or "CWF6+FWX Mountain View, California"

Latitude and longitude coordinates, optionally with vehicle heading

Fine-tune your route options based on your needs and goals:

Select fuel or energy-efficient routes for your vehicle's engine type: Diesel, Electric, Hybrid, Gas. For more information, see Get an eco-friendly route .

Set fine-grained options for traffic calculation, letting you make quality vs latency trade off decisions. For details, see Specify how and if to include traffic data .

Set vehicle heading (direction of travel) and side-of-road information for waypoints to increase ETA accuracy. For details, see Specify vehicle heading and side of road .

Specify pass-through vs terminal locations and safe stopover locations. For details, see Set a stop along a route and Set a point for a route to pass through .

Request toll information, along with route distance and ETA. For details, see Calculate toll fees for a route .

Control your latency and quality by requesting only the data you need using a field mask, which helps you avoid unnecessary processing time and higher request billing rates. For details, see Choose what information to return .

Get a matrix of possible routes

The Routes API Compute Route Matrix method provides a matrix of information for recommended routes between multiple start and end points, including distance and estimated arrival times, to help you choose the best origins and destinations based on your business needs. You can request these kinds of distance data:

Distance for a selected travel mode

Distance in kilometers or miles

Estimated travel time in traffic

With the distance data, you can determine the most efficient way to route passengers, shipments, or workers between multiple possible origins and destinations.

You can stream elements of the response before the entire matrix has been calculated, lowering response latency.

You can specify multiple origins and destinations per server-side request with the number of origins times the number of destinations up to 625.

How the Routes API works

The Routes API has two methods: ComputeRoutes and ComputeRouteMatrix .

ComputeRoutes

The Routes API ComputeRoutes method accepts an HTTP POST request with a JSON request body that contains the request details. Required are an origin, destination, travelMode, and a field mask to specify which fields to return.

The service then calculates the requested route, and returns the fields you've requested.

ComputeRouteMatrix

The Routes API ComputeRouteMatrix accepts an HTTP POST request with a JSON request body that contains the request details. Required are at least one origin, two or more destinations, travelMode, and a field mask to specify which fields to return.

The response contains the possible routes for the combination of all origin and destination waypoints.

The following table summarizes the resources available through the Routes API along with the data it returns.

How to use the Routes API

Available client libraries.

For a list of the available client libraries for the Routes API, see Client libraries .

What's next

  • Available route options
  • Choose what information to return
  • Migrate from Directions API or Distance Matrix API
  • Migrate from the Routes API preview to GA

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-05-13 UTC.

When you use Google Maps Platform to plot multiple locations, you can see nearby markers visually. However, their true distance isn’t always clear, especially when factoring in traffic. You can quantify how close two points are by calculating the distance using the Maps Javascript API, but when you want to determine many distances at once, the Distance Matrix API can help you out and get all the data you need in a single call. For example, you can narrow a list of restaurants by delivery time, assign multiple delivery drivers based on proximity, or determine the nearest technician to a customer to dispatch. 

In this post, we’ll show you how to use the Distance Matrix API using a common use case–technician dispatching. First, it’s important to understand all the data that is returned from the API, so we’ll start with a basic example identifying the driving distances between major Midwestern cities.

Add map markers for each city

Before you calculate any distances, it’s useful to see the locations on a map. To do that, you’ll need to create markers for our quintet of cities: Chicago, Milwaukee, Detroit, Indianapolis, and St. Louis.

Here’s some HTML and JavaScript to create a map with these cities marked:

Find your API Key in the Google Cloud Console and put it in place of YOUR_API_KEY in the code above. In addition to creating a basic map centered in the midwestern United States, the code above creates five markers—one for each of the cities in our example.

When you save the code and load it in a browser, you’ll see a map like the one above. You can probably tell just by looking which city is closest to Chicago, but let’s see how a distance matrix can quantify the solution.

Visualize the distance matrix with a mileage table

The concept behind the Distance Matrix API comes from a time before smartphones and ubiquitous GPS. Travelers would reference printed materials to determine driving distances and durations. You could find two-dimensional mileage tables with city names along the left side and top. Within those tables, found on a paper map in your car or posted on a wall at a gas station, were the distances between the cities in each row and column.

If you were near Chicago, for example, you could quickly read across the first row to see the distance to Milwaukee (92 miles) or Detroit (281 miles). The diagonal pattern of empty cells is a quick heads up that you’re looking at a mileage table—there’s no driving from Chicago to Chicago, after all.

The Distance Matrix API is a modernized take on this glove box classic. You have complete control over the origins in each row and destinations in each column, which allows you to recreate a classic distance matrix, or use a single origin with multiple destinations. Best of all, there’s no need to print these out. You can make a request and have your answer in JSON in seconds.

Calculate drive times from multiple origins

Distances between cities may be fine for paper road maps, but today’s applications have more granular needs that can be supported by the Distance Matrix API. For example, the API is useful for dispatch and delivery, where you have a number of origins or destinations. Let’s see how you can use the Distance Matrix API to choose the closest repair technician.

This usage of the Distance Matrix API includes one destination (the customer) and multiple origins (each potential technician). We’ll assume you know the current position of each technician, such as from GPS.

Add the following code to your map JavaScript after the  // Add Distance Matrix here comment:

Since there is a single destination and multiple origins, the results will include multiple rows, each with a single result. In visual distance matrix terms, you’ll be parsing a single column. When the results are returned to the callback function, the code simply logs the response to the browser console. You can inspect it with your browser’s developer tools, or review the JSON payload:

The origin and destination addresses are returned at the top level of the response. They can help you make sense of which distance is which. The origins, which were input as latitude/longitude coordinates, have automatically been reverse geocoded to the nearest address.

The rows array has three items, one for each origin (the technicians). Within each row, there is an elements array that includes a result for each destination. Individual results include a status, duration, and distance.

Now that you understand the Distance Matrix data, you’ll want to use it. For example, you could populate a table, share distances on the map, or search through for the shortest drive.

Find the nearest location by drive time

We want to dispatch the nearest technician to the customer location. To do that, we’ll parse the distance matrix JSON to find the shortest drive time.

Add this code after the console.log of the Distance Matrix callback:

This code loops through all the rows, looking in the first (and only) element of each to find the driving duration. Next, it compares drive time to the current lowest time. By the end, you’ll have discovered the closest location.

You have now parsed the results to find the closest technician—in this case it’s the one at 204 S Clark St, who is only four minutes away. Here, it’s communicated with a JavaScript alert, but in reality you would assign the technician to the customer, likely with a call to your own backend system.

This post gave a few examples of using the Distance Matrix API but there’s much more to explore. You can build off these examples to make your own dispatch service, delivery route planner, or even old school mileage table. Once you have a route selected, you can use the Directions Service to plot it on the map, completing the visual for your users. 

For more information on Google Maps Platform, visit our website .

  • ATTOM Cloud
  • Property API
  • Property Navigator (formerly GeoData Plus)
  • Property Navigator* *formerly GeoData Plus

Predicting Future Travel Times with the Google Maps APIs

by ATTOM Team | Apr 25, 2018 | ATTOM Insights , Property Data Dynamics

google maps api estimated travel time

Google announced a new feature in the  Google Maps API , the ability for developers to compute travel distance and time between a number of points. This is an interesting feature which can be directly applied to the Real Estate Industry. Their launch partner is  Redfin  (note: Redfin is a current client of Onboard).

“Taking the guesswork out of knowing how long it will take to drive between homes will help us provide a better customer experience to our users” – Curtis Howell, Product Manager Customer Engagement, Redfin
  • Duration and Distance  – Estimate travel time and distance based on a recommended route.
  • Driving – Indicates distance calculation using the road network.
  • Walking – Requests distance calculation for walking via pedestrian paths & sidewalks (where available).
  • Bicycling – Requests distance calculation for bicycling via bicycle paths & preferred streets (where available).
  • Transit – Requests distance calculation via public transit routes (where available). One or more transit modes can be specified: Bus, Subway, Train, Tram and/or Rail.
  • Traffic  – Request using Best guess, Optimistic or Pessimistic calculations based both historical traffic conditions and live traffic. Optionally you can specify either a departure_time or an arrival_time.
  • Search Boundary  – The Google API calculates the distance between two known points. It does not offer the ability to determine the outer boundary based on time and/or distance from a location. This is important in Real Estate because the consumer would like to know all properties that are within commuting time/distance from work.
  • Cost  – Standard  billing  based on usage. First 2,500 elements are free. $0.50/1,000 up to 100,000 after that. However keep in mind with that plan Google reserves the right to serve ads. You will most likely want to upgrade to their Premium service,  Google Maps API for Work . In which case you will need to speak with a sales person and negotiate pricing.
  • Google Map Display Required  – “Use of the Google Maps Distance Matrix API must relate to the display of information on a Google Map; for example, to determine origin-destination pairs that fall within a specific driving time from one another, before requesting and displaying those destinations on a map. Use of the service in an application that doesn’t display a Google map is prohibited.”

How we can help

Onboard Informatics has an  IDX API  which enables our clients to offer commute search in two ways:

  • Flat Fee Pricing  – Onboard prices access to the IDX API based on a monthly fee per MLS feed.
  • Technology Agnostic  – The API produces XML or JSON, you decide. And can be used with any mapping software. We also offer up geographic boundaries in a variety of formats; GeoJSON, KML, WKT, and/or ESRI shapes.

If you are interested in finding out more about our solutions, contact us today. Overall, the Google announcement today is positive.  We’re always excited when companies push for progress in real estate technology and work toward continuing to improve the experience for home buyers and sellers everywhere.

  • Share this post

Interested in purchasing the data cited in our articles?

Or learn more about how businesses are leveraging ATTOM’s property and real estate data? Please complete the form below to connect with a data expert.

Tags related to this post

About the author.

Avatar photo

  • All posts by ATTOM Team

STAY CONNECTED

Unlocking the Power of Building Footprints webinar promo

  • Most Recent
  • Foreclosures
  • Hazard / Risk
  • Home Flipping
  • Home Sales & Prices
  • Mortgage Origination
  • Single Family Rental
  • #figuresfriday
  • Data Solutions
  • Delivery Solutions
  • Marketing Solutions

Popular Posts

Q1 2024 Foreclosure Report

TravelTime Logo

Google Distance Matrix API vs. the TravelTime API: Which is Best for You?

9 minute read

By: victoria akinsowon

This post compares the product features of the Google Distance Matrix API and the TravelTime API. If you’re just looking to compare pricing and API limits, read this post instead. It compares prices with Google, Mapbox, Here, Graphhopper and more.

In this post, we’ll compare the differences between Google’s Distance Matrix API and the TravelTime API, including their matrix functionality, map services and support.

Distance Matrix CTA

What is the Travel Time Matrix API?

The Travel Time Matrix API allows you to calculate travel times to thousands of locations simultaneously, within milliseconds and for any mode of transport.

TravelTime also has two other APIs:

  • Isochrone API: Create isochrone maps to visualise where you can reach within a time limit
  • Routes API: Generate A to B routes, including turn-by-turn directions
  • Consumer-facing websites and apps: You can use the TravelTime API to filter, rank and list location search results by travel time on your website or app. The API can filter thousands of locations in milliseconds and is used in a range of different use cases, including recruitment and property websites.
  • Location analysis: You can also use TravelTime for location analysis , including office relocation or retail site selection. Here, the API can be used in a number of GIS software, including ArcGIS, QGIS and Alteryx.

What is the Google Distance Matrix API?

The Google Distance Matrix API allows you to calculate travel distance and time between multiple origins and destinations.

Common use cases for the Distance Matrix API include vehicle routing and analysis of traffic systems.

At a glance: the Google Distance Matrix API vs. TravelTime API

cta banner

Comparing distance matrix features

In this section, we’ll compare the functionality of Google’s Distance Matrix API with that of the TravelTime API.

The TravelTime API allows you to calculate a matrix of travel times between thousands of origins and destinations. Additionally, you can set a maximum travel time cut-off to automatically filter locations as reachable or unreachable.

Finally, TravelTime currently supports over 100 countries , with public transport data available for the vast majority of them. You can check out our list of supported countries here .

The Google Distance Matrix API lets you calculate the travel times for up to 25 origins or 25 destinations in one request.

‍ Key differences

1. matrix speed & performance.

With TravelTime’s performance and limits, you can calculate large volumes of times in under 100 milliseconds. This means it can be used within consumer-facing location searches without impacting app load times.

In contrast, it would be too slow to do this with Google’s Distance Matrix API if the consumer app has more than 25 locations.

2. Matrix multi-modal transport options

The TravelTime API calculates travel times for all transport modes. For public transport, you can choose one mode of public transport (which includes bus, train, subway, tram, coach and ferry) or you can also combine modes. This includes driving and train combined, driving and ferry combined, and cycling and ferry combined.

The Google Distance Matrix API calculates distances and times for public transport, driving, walking and cycling.

3. Fare data options

TravelTime provides fare data for public transport in the UK only. This includes data for standard, weekly, monthly and annual tickets.

Google provides fare data for public transport where available. This includes data for a standard ticket.

Comparing map services

Both Google and TravelTime also offer map services in addition to their matrix functionality. In this section, we’ll compare the map services of their APIs.

Isochrone API

Isochrones are maps that allow you to visualise all reachable locations within a time limit and by mode of transport.

isochrone

With the TravelTime API, you can create high-resolution isochrones for any type of public transport, as well as driving, cycling and walking. You can also combine transport modes – for example, to see where you can travel to within 30 minutes by driving and train. 

The API comes with adjustable parameters, which means you can customise your desired maximum walk times, transport connection times and more. What’s more, you have the flexibility to create isochrones through the API or, alternatively, though one of our dedicated GIS plugins .

In contrast, the Google Distance Matrix API doesn’t support the creation of isochrones through its API, nor does Google itself provide a built-in way to generate isochrones. 

You can use the TravelTime Routing API to create A-to-B routes, including turn-by-turn directions, and visualise these routes on a map or as a set of door-to-door instructions.

This can be done for all modes of transport, including all forms of public transport.

google maps api estimated travel time

If you want to do routing via Google, you will need to use Google’s separate Directions API.

You can use the Directions API to receive directions between locations for different transport modes, including driving, walking, cycling and public transport. Note that this is priced separately.

Geocoding and map tiles

Free unlimited access to geocoding and map tiles is included with every paid TravelTime API plan.

For geocoding, coordinates can be used to display addresses on a map or as inputs for other TravelTime API endpoints.

You will need to use Google’s separate Geocoding API to return geocoding information, and its separate Maps API for map tiles.

cta banner

How to create a distance matrix with the TravelTime API

To create a distance matrix, you first need to get a TravelTime API key .

Creating a distance matrix requires a single POST request, with a number of required parameters. These include:

  • Transportation type (these include ‘driving’, ‘public_transport’ and ‘walking’)
  • Departure or Arrival time
  • Travel time

To calculate a matrix with multiple origins and multiple destinations , you can simply add multiple searches into the request. Each of these searches can then include up to 2,000 locations. Learn more about creating a distance matrix here.

Alternatively, try our Matrix Developer Playground for free here .

TravelTime  

As standard, TravelTime’s support plans come with documentation, a comprehensive knowledge base and tutorials.

However, there are additional tiers that come with even more support. For example, the Standard tier includes a support portal, email support, onboarding workshop and a dedicated Customer Success Manager.

The Premium tier includes all the above, plus a 12-hour guaranteed first response time and 99.9% service uptime SLA.

  • ‍ Discover our support plans here

Google 

Support for the Google Distance Matrix API is comprised of a Stack Overflow Community, where you can ask technical questions, and is monitored by members of the Google Maps Platform team.

Alternatively, you can create support cases directly to the Maps Support Team – although this is restricted to Project Owners, Project Editors and Tech Support Editors only. According to Google, response times can take up to 24 hours on weekdays.

What customers say about the TravelTime API

Comprehensive transport data.

“TravelTime was the tool that stood out: it was the most reliable and the scope of its transport data was broader than any other service we considered.”

- Hugo Michalski, Co-Founder & CTO, Side

google maps api estimated travel time

$1 See how Side uses TravelTime

Layering travel time data with additional datasets

“It’s been great to analyse the data we get from TravelTime alongside other datasets like census or population data, to tell us how many people we can reach from certain locations.” 

- Tim Hirst, Data Scientist, SEGRO  

google maps api estimated travel time

Learn how SEGRO uses TravelTime

Better user experience

“TravelTime has enriched our user experience and increased conversions by 10%."

- Christophe De Rassenfosse, Chief Product Officer, Totaljobs

google maps api estimated travel time

See how Totaljobs uses TravelTime

Reliable and fast

“The TravelTime API is easy to use, reliable and fast - it’s an asset to our search functionality.” 

- Leo Lapworth, Web Operations Director, Foxtons

google maps api estimated travel time

Learn how Foxton uses TravelTime

TravelTime vs. Google: Which solution is best for me?  

Both the Google’s Distance Matrix API and the Travel Time Matrix API can calculate travel times and distances between locations with different transport modes.

However, the TravelTime API is more cost-effective than the Google Distance Matrix API for calculating large matrices of travel times at once.

And with a dedicated in-house data team , TravelTime offers a comprehensive and broad range of transport data, which includes all forms of public transport. This means that you can easily calculate travel times by the transport mode of your choice without breaking the bank.

TravelTime also comes with additional functionality that you may not have previously considered.

These include the ability to visualise travel times on a map (isochrones), as well as routing, geocoding and map tiles – all of which are included within all paid plans. And unlike Google, you won’t have to pay for separate APIs if you were looking to use these additional map services.

To learn more about what you can do with the TravelTime API,  check out our documentation  or to try TravelTime for yourself,  sign up for a free API key .

Calculate thousands of travel times with the TravelTime API

Read related articles

featured

' height=

Official Blog

Predicting future travel times with the google maps apis.

  • If your application is used for scheduling deliveries, and you want to ensure you’ve allowed enough time between deliveries so your drivers won’t be late, you might want to use the pessimistic travel time estimates.
  • On the other hand, if you’re building a thermostat app, and you want the house to be warm by the time your user arrives home from work, you might want to use the optimistic travel time estimate to calculate when the user is likely to arrive.
  • If you want to give your user an estimate of the most likely travel time to their destination, the default best_guess traffic model will give you the most likely travel time considering both current traffic conditions and historical averages.

google maps api estimated travel time

“Taking the guesswork out of knowing how long it will take to drive between homes will help us provide a better customer experience to our users”  –  Curtis Howell, Product Manager Customer Engagement, Redfin

Share on Google+

  • #innovationupgrade
  • #InspireGirls
  • #moregoogleapps
  • #SysAdminDay
  • #throwbackthursday
  • #top10trust
  • Admin console
  • Android for Work
  • Android for Work Live
  • Android Marshmellow
  • Android Nougat
  • Android security
  • Android security tips
  • Apps Adventures
  • apps script
  • Armed Forces Day
  • Asia Pacific
  • Atmosphere Live
  • Audi Connect
  • Chomebox for Meetings
  • Chrome Device Management
  • Chrome digital signage
  • Chrome for Business
  • Chrome for Work
  • Chrome Frame
  • Chromebooks
  • Chromebooks for Business
  • Chromebooks for Education
  • Chromebooks for Work
  • Chromebox for digital signage
  • Chromebox for meetings
  • Chromebox for signage
  • Chromeboxes
  • Clearing Kosovo
  • cloud computing
  • cloud computing gonegoogle
  • cloud computing gonegoogle Google Apps
  • cloud computing gonegoogle Google Apps google docs small business success story
  • cloud computing gonegoogle Google Apps google docs small business success story switch
  • cloud datastore
  • cloud platform
  • Cloud Platform Live
  • cloud print
  • cloud series
  • cloud services
  • collaboration
  • Control Panel
  • customer love
  • Customer story
  • Customer support
  • Customer testimonial
  • data centers
  • data processing amendment
  • data protection
  • Digital Learning Day
  • Drive for Education
  • drive sharing
  • earth and maps
  • Education on Air
  • Global Partner Summit
  • Gone Google
  • Google AdWords
  • Google App Engine
  • Google Apps
  • Google Apps Blog
  • Google Apps for Business
  • Google Apps for Education
  • Google Apps for Government
  • Google Apps for Work
  • Google Apps Marketplace
  • Google Apps Reseller
  • Google Apps Script
  • Google Apps Vault
  • Google BigQuery
  • Google Calendar
  • Google Calendar app
  • Google Certified Teachers
  • Google Chrome
  • Google Chromebases
  • Google Classroom
  • Google Cloud Datastore
  • Google Cloud DNS
  • Google Cloud Platform
  • google cloud storage
  • Google Cloud Vision API
  • google commerce search
  • Google Compute Engine
  • Google Docs
  • Google Domains
  • Google Draw
  • Google Drive
  • Google Drive for Work
  • Google Earth
  • Google Earth Engine
  • Google Earth Enterprise
  • Google Earth Images
  • Google Earth Pro
  • Google Email Security and Archiving
  • Google Enterprise
  • Google Enterprise Search
  • Google Expeditions
  • Google for Education
  • Google for Education Partner Program
  • Google for Education Training Center
  • Google for Entrepreneurs
  • Google for Work
  • Google for Work and Google for Education Partner Program
  • Google for Work partner program
  • Google Forms
  • Google Green
  • google groups
  • Google Hangout
  • Google Hangouts
  • Google Keep
  • Google Maps
  • Google Maps API
  • Google Maps APIs
  • Google Maps Coordinate
  • Google Maps Engine
  • Google Maps Engine Pro
  • Google Maps Engine public data program
  • Google Maps for Business
  • Google Maps for Work
  • Google Maps Gallery
  • Google Maps Tracks API
  • Google Message Continuity
  • google message security
  • Google Mobile Device Management
  • Google My Maps
  • Google My Maps Pro
  • Google Places API
  • Google Play
  • google play for education
  • Google Prediction API
  • Google Research tool
  • Google Science Fair
  • Google Search Appliance
  • Google Security Key
  • Google Sheets
  • Google Site Search
  • google sites
  • Google Slides API
  • Google Smart Lock
  • Google spreadsheets
  • Google Springboard
  • google storage
  • Google Storage for Developers
  • Google Translate
  • Google Vault
  • Google Video
  • Google Wave
  • Google+ api
  • Google+ Communities
  • GSA for Commerce
  • Hangout on Air
  • Hangouts on Air
  • hints and tips
  • Inbox by Gmail
  • international trade
  • Internet Explorer
  • large business
  • manufacturing
  • Mapping a better world
  • marketplace
  • marketplace highlights
  • medium business
  • mobile management
  • model contract clauses
  • Mother's Day
  • mpstaffpick
  • new features
  • Niagara International Transportation Technology Coalition
  • OpenID Connect
  • Partner Showcase
  • Place Summaries
  • product ideas
  • productivity
  • Quickoffice
  • Receptionist's Day
  • Safer Internet Day
  • Security Key
  • small business
  • Small Business Week
  • Small businesses
  • spam and security trends
  • success story
  • System Admin
  • Teamwork 2015
  • Thanksgiving
  • Transport and Logistics
  • University of Calgary
  • Veteran Owned Businesses
  • Veterans Day
  • Veterans Day 2013
  • Veterans Day 2014
  • women in tech
  • Women's History Month
  • Work Resolutions

Google+

Useful Links

Company-wide.

  • Official Google Blog
  • Public Policy Blog
  • Student Blog
  • Android Blog
  • Chrome Blog
  • Lat Long Blog
  • Developers Blog
  • Ads Developer Blog
  • Android Developers Blog

Syntax Byte

Excel, JavaScript, Android, and other Programming Tutorials

Excel Function to Calculate Travel Time and Distance using Google Maps API with VBA

In this article, we will create an Excel function to calculate the distance between two addresses using the Google Maps directions API. This will allow you to get the travel time between the two locations. The format of the function will be as follows: =TRAVELTIME(origin, destination, api_key) , =TRAVELDISTANCE(origin, destination, apikey) . The origin and destination will be strings, and can be either an exact address or the name of a place. In order to use the function, an API key is required. The “Getting Started” page can help you with this: http://bit.ly/googlemapsgettingstarted . Create a new project and make sure the Directions API is added.

Step 1: Create a new macro file and add VBA-JSON

Because the Google Maps Directions API is a JSON API, we will use VBA-JSON to make it easy to use the results from the web request. You can download the latest version from here: https://github.com/VBA-tools/VBA-JSON/releases . Download and extract the zip file. Then, open your macro file. Open the Visual Basic Editor (Alt + F11).

google maps api estimated travel time

In order to import the VBA-JSON file, go to File > Import File… (Ctrl + M). Select JsonConverter.bas . A JsonConverter module will appear in the sidebar.

google maps api estimated travel time

Next, make sure the appropriate references are enabled. Go to Tools > References… In addition to the references already selected, check off “Microsoft Scripting Runtime” (for Dictionary support needed by VBA-JSON) and “Microsoft WinHTTP Services, version 5.1” (to make the HTTP request to the API). If you require support for Excel for Mac, you will need to install VBA-Dictionary from the author of VBA-JSON. More details can be found at the bottom of the project homepage: https://github.com/VBA-tools/VBA-JSON .

google maps api estimated travel time

Step 2: Create the functions

With the references configured, we can now write the code for the function. The code is relatively simple. It is simply takes the three parameters and formats them into a web request. The response of the web request is then parsed by VBA-JSON and the relevant variable returned. Note that the request may return multiple routes, but then function simply returns the time of the first route. The default mode is driving, but refer to the Directions API documentation for information on other modes and adjust the strURL variable accordingly.

To insert the code, create a new module with Insert > Module. Then paste the following code:

Save the file. You should now be able to use the functions from within Excel. Place your API key in cell A1, then try the following: =TRAVELTIME("24 Sussex Drive Ottawa ON", "Parliament Hill", A1) . This returns a travel time of about 435 seconds. If you would like this to be displayed in minutes and seconds, try this function: =FLOOR.MATH(A8/60)&" minutes "&MOD(A8, 60)&" seconds" where A8 is the cell with the travel time in seconds. This prints a helpful “7 minutes 15 seconds” for the 24 Sussex example. We can also find the distance. Try the following: =TRAVELDISTANCE("24 Sussex Drive Ottawa ON", "Parliament Hill", A1) . It returns a distance of 2667 meters. Convert to kilometers with this: =ROUND(A9/1000, 1)&" km" .

Note: The Google Maps Directions API always returns distances in meters. Convert to KM or Miles as you wish. This can be done in Excel or by modifying the functions in VBA.

That’s it! You should now have a working travel time function. All you need now is a list of addresses to use it with. If you would like to pull a list from the web or local JSON file, check out Import JSON Data in Excel 2016 or 2019 or Office 365 using a Get & Transform Query .

COMMENTS

  1. Using Google Maps API to get travel time data

    25. Yep, this is definitely possible using the API. You can construct a GDirections object without a map or directions div. You can do a load request from A to B and then call the getDuration method to get the total travel time. First you need to create a directions object: // no need to pass map or results div since.

  2. Predicting future travel times with the Google Maps APIs

    Predictive travel time uses historical time-of-day and day-of-week traffic data to estimate travel times at a future date. This makes it easier than ever to predict how long it will take to get somewhere and suggest the best route even when the departure time is far in the future. Since traffic conditions in the future will vary greatly, we ...

  3. Distance Matrix API overview

    The Distance Matrix API uses any number of origins (starting points) and destinations, and returns the distance and travel time between each origin and all requested destinations, starting with the first origin in the request and proceeding step-wise to the next. For example, if your request specifies A and B as origins, and C and D as ...

  4. Google Maps Platform Documentation

    Make a distance matrix request. Get the travel distance and journey duration for a matrix of origins and destinations. Use Java, Python, Go, or Node.js client libraries to work with Google Maps Services on your server. Get the OpenAPI specification for the Distance Matrix API, also available as a Postman collection.

  5. Distance Matrix Service

    To view your list of enabled APIs: Go to the Google Cloud Console . Click the Select a project button, then select the same project you set up for the Maps JavaScript API and click Open. From the list of APIs on the Dashboard, look for Distance Matrix API. If you see the API in the list, you're all set. If the API is not listed, enable it: At ...

  6. Distance Matrix API request and response

    The following URL initiates a Distance Matrix request for driving distances between Boston, MA or Charlestown, MA, and Lexington, MA and Concord, MA. The request includes a departure time, meeting all the requirements to return the duration_in_traffic field in the Distance Matrix response. https:

  7. Routes API Overview

    Routes API Overview. The Routes API is a service that accepts an HTTPS request and returns either the ideal route between two locations, or distances and travel times for a matrix of routes between different origin and destination locations. Note: If you are migrating from the Directions API or Distance Matrix API, see migration instructions ...

  8. How to Use the Distance Matrix API

    We'll assume you know the current position of each technician, such as from GPS. Add the following code to your map JavaScript after the // Add Distance Matrix here comment: const service = new google.maps.DistanceMatrixService(); // instantiate Distance Matrix service. const matrixOptions = {.

  9. Google Maps APIs Predictive Travel Time Feature

    Predictive travel time uses historical time-of-day and day-of-week traffic data to estimate travel times at a future date. This makes it easier than ever to ...

  10. Predicting Future Travel Times with the Google Maps APIs

    Google announced a new feature in the Google Maps API, the ability for developers to compute travel distance and time between a number of points. This is an interesting feature which can be directly applied to the Real Estate Industry. Their launch partner is Redfin (note: Redfin is a current client of Onboard).

  11. Google Distance Matrix API vs. the TravelTime API: A Comparison

    Both the Google's Distance Matrix API and the Travel Time Matrix API can calculate travel times and distances between locations with different transport modes. However, the TravelTime API is more cost-effective than the Google Distance Matrix API for calculating large matrices of travel times at once. And with a dedicated in-house data team ...

  12. Getting Travel Distance and Travel Time from Google Maps API V3

    2. I'm using Google Maps API V3 to draw the walking route between 2 points startPosition and endPosition using google.maps.DirectionService. It should then print to console the route's distance and travel duration. Problem: Although the code does draw the route successfully, it seems that directionsDisplay.setDirections lack a callback function ...

  13. google maps api

    Current Problem: Tried to use the Google Distance Matrix and Google Diretions API's. Both do not allow a travel mode of driving combined with an arrival time as input. Question: What API can be used with the (batch size 1 - 50) input of a desired arrival time (/datetime) and a transport mode of driving to give an estimated departure time/travel ...

  14. Full article: Estimating O-D travel time matrix by Google Maps API

    Figure 8 shows that travel time by the Google Maps API approach is consistently longer than that by the ArcGIS Network Analyst approach. The estimated travel time by either method correlates well with the (Euclidean) distance from the city center (with a R 2 = 0.91 for both methods). However, the regression model of travel time against ...

  15. Estimating O-D travel time matrix by Google Maps API: implementation

    the Google Maps site into an external website and overlay specific data on to the site (Mercurio 2008). In the follow-ing, we will discuss how to use the Google Maps API to estimate the travel time between origins and destinations without reloading the web page or displaying portions of the map. As shown in Figure 1, the process begins with ...

  16. Travel Time using Google API

    how to calculate the time needed to get from one point to another using google map api? 3. ... Google Maps API: Travel time with current traffic. 5. travel time between two locations in Google Map Android API V2. 0. Google Directions API Duration In Traffic. 0. Google maps api departureTime in directionsService. 1. How to show duration trip in ...

  17. Predicting Future Travel Times with the Google Maps APIs

    Predictive travel time uses historical time-of-day and day-of-week traffic data to estimate travel times at a future date. This makes it easier than ever to predict how long it will take to get somewhere and suggest the best route even when the departure time is far in the future. ... you might want to use the optimistic travel time estimate to ...

  18. GitHub

    Google Maps Graph A visual representation of how long your trip will be based off of the time of day. How it works. Simply tell it where you are starting from and where you are going. You can also select the algorithm that Google will use to check your estimated travel time.

  19. google maps api

    IMO, flight travel time is directly correlated to distance. This is because flights are mostly directlines between source and destination. Thus, you can use the Google API Distance matrix to calculate distance between points, then divide by the average speed of commercial flights, which is ~550mph. then, you get your flight time.

  20. Google Maps Dircetions API

    10. I use the Google Directions API for calculating the needed time between 2 places. The API gives me an option departure_time, where I can pass the timestamp of the departure time (or "now"). Then the answer is the duration_in_traffic. This is working really great. But I need to show the amount of time that the user needs with his car, when ...

  21. Excel Function to Calculate Travel Time and Distance using Google Maps

    In this article, we will create an Excel function to calculate the distance between two addresses using the Google Maps directions API. This will allow you to get the travel time between the two locations. The format of the function will be as follows: =TRAVELTIME(origin, destination, api_key), =TRAVELDISTANCE(origin, destination, apikey).