Get Started

The Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations, based on the recommended route between start and end points.

Sample request and response

Access the Distance Matrix API through an HTTP interface, with requests constructed as a URL string, using origins and destinations, along with your API key.

The following example requests the distance matrix data between Washington, DC and New York City, NY, in JSON format:



curl -L -X GET ''


var axios = require('axios');

var config = {
  method: 'get',
  url: '',
  headers: { }

.then(function (response) {
.catch(function (error) {


import requests

url = ""

headers = {}

response = requests.request("GET", url, headers=headers, data=payload)



OkHttpClient client = new OkHttpClient().newBuilder()
Request request = new Request.Builder()
  .method("GET", null)
Response response = client.newCall(request).execute();


require "uri"
require "net/http"

url = URI("")

https =, url.port)
https.use_ssl = true

request =

response = https.request(request)
puts response.read_body


package main

import (

func main() {

  url := ",%20DC&destinations=New%20York%20City,%20NY&units=imperial&key=YOUR_API_KEY"
  method := "GET"

  client := &http.Client {
  req, err := http.NewRequest(method, url, nil)

  if err != nil {
  res, err := client.Do(req)
  if err != nil {
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {


The OpenAPI specification is also available as a Postman collection.

Run in Postman

Try it! You can test this by entering the URL into your web browser (be sure to replace YOUR_API_KEY with your actual API key). The response includes the distance and duration between the specified origins and destinations.

View the developer's guide for more information about building request URLs and available parameters and understanding the response.

Below is the sample response in JSON and XML formats:


  "destination_addresses": ["New York, NY, USA"],
  "origin_addresses": ["Washington, DC, USA"],
              "distance": { "text": "228 mi", "value": 367439 },
              "duration": { "text": "3 hours 53 mins", "value": 14003 },
              "status": "OK",
  "status": "OK",


 <origin_address>Washington, DC, USA</origin_address>
 <destination_address>New York, NY, USA</destination_address>
    <text>3 hours 53 mins</text>
    <text>228 mi</text>

OpenAPI specification

The OpenAPI specification is published for this API and available on GitHub.

Get OpenAPI Specification

Postman Collection

The OpenAPI specification is also available as a Postman collection.

Run in Postman

Start coding with our client libraries

Client libraries make developing with the Google Maps web service APIs easier by providing simple, native implementations of common tasks, such as authentication, request throttling and automatic retry. The Distance Matrix API is available in the Java Client, Python Client, Go Client and Node.js Client for Google Maps Services.

Authentication, quotas, pricing, and policies


To use the Distance Matrix API, you must first enable the API and obtain the proper authentication credentials. For more information, see Get Started with Google Maps Platform.

Quotas and pricing

Review the usage and billing page for details on the quotas and pricing set for the Distance Matrix API.


Use of the Distance Matrix API must be in accordance with the API policies.

Learn more

There’s more you can do with the Distance Matrix API, like requesting distance data for different travel modes, requesting distance data in different units (for example, kilometers or miles), and estimating travel time in traffic. See the Distance Matrix API developer guide for more examples and other details.

The Distance Matrix API developer guide is intended for developers who wish to compute travel distance and time between a number of points within maps provided by one of the Google Maps APIs. It provides an introduction to using the API and reference material on the available parameters.