> [!NOTE]
> This product is in [Legacy status](https://developers.google.com/maps/legacy.md.txt). As of October 2026, Distance Matrix API (Legacy) can no longer be enabled for new Google Cloud projects. Existing projects remain fully supported. For new features and improved performance, [migrate to the Routes
> API](https://developers.google.com/maps/documentation/routes/migrate-routes).

## Sample request and response

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

### URL

```
https://maps.googleapis.com/maps/api/distancematrix/json
  ?destinations=New%20York%20City%2C%20NY
  &origins=Washington%2C%20DC
  &units=imperial
  &key=YOUR_API_KEY
```

### curl

```bash
curl -L -X GET 'https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington%2C%20DC&destinations=New%20York%20City%2C%20NY&units=imperial&key=YOUR_API_KEY'
```

**Try it!** Test this request by entering the URL into your web browser - be
sure to replace `YOUR_API_KEY` with [your actual API
key](https://developers.google.com/maps/documentation/distance-matrix/get-api-key). The response shows the distance and duration between the specified
origins and destinations.

Learn how to [build request URLs](https://developers.google.com/maps/documentation/distance-matrix/distance-matrix.md.txt),
including all available parameters.

This code sample is in JSON and XML formats:

### JSON

```json
{
  "destination_addresses": ["New York, NY, USA"],
  "origin_addresses": ["Washington, DC, USA"],
  "rows":
    [
      {
        "elements":
          [
            {
              "distance": { "text": "228 mi", "value": 367654 },
              "duration": { "text": "3 hours 55 mins", "value": 14078 },
              "status": "OK",
            },
          ],
      },
    ],
  "status": "OK",
}
```

### XML

```xml

 OK
 Washington, DC, USA
 New York, NY, USA
 
  
   OK
   
    14078
    3 hours 55 mins
   
   
    367654
    228 mi
   
  
 
```

Check the developer's guide to [understand the response](https://developers.google.com/maps/documentation/distance-matrix/distance-matrix.md.txt#distance-matrix-responses).