# Distance Calculator API

> Distance Calculator computes the distance between two coordinate pairs in miles and kilometers. Supply two latitude and longitude points anywhere in the world to receive both distances, plus the nearest city and state for points in the US.

**Endpoint:** `GET https://api.apiverve.com/v1/distancecalculator`  
**Category:** Geography  
**Cost:** 2 credits per call  
**Canonical page:** https://apiverve.com/marketplace/distancecalculator

## Overview

A distance calculator API for the distance between two latitude and longitude points. Send lat1, lon1, lat2 and lon2 and the API returns the straight-line (great-circle) distance between the two points in miles and kilometers. The Free plan returns both distances, so you can try the distance calculator API free, and paid plans add the compass bearing, the direction and a rough driving-time estimate. The distance is measured over the earth's surface, not along roads.

## Authentication

Every call carries your key in an `x-api-key` header. The same key works across the whole
APIVerve catalog — there are no per-API subscriptions. Responses always use the same three
top-level keys: `status`, `error`, and `data`.

## Example request

```bash
curl "https://api.apiverve.com/v1/distancecalculator?lat1=36.7783&lon1=-119.4179&lat2=34.0522&lon2=-118.2437" \
  -H "x-api-key: YOUR_API_KEY"
```

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `lat1` | number | Yes | The latitude of the first location. range -90-90 |
| `lon1` | number | Yes | The longitude of the first location. range -180-180 |
| `lat2` | number | Yes | The latitude of the second location. range -90-90 |
| `lon2` | number | Yes | The longitude of the second location. range -180-180 |

## Response fields

- `distanceMiles` — number · Distance between the two locations in miles
- `distanceKm` — number · Great-circle distance between the two points in kilometres
- `location1` — object · Resolved origin location
  - `location1.latitude` — string · Latitude of the origin in decimal degrees
  - `location1.longitude` — string · Longitude of the origin in decimal degrees
  - `location1.city` — string · City the origin resolves to
  - `location1.state` — string · State or region the origin resolves to
- `location2` — object · Resolved destination location
  - `location2.latitude` — string · Latitude of the destination in decimal degrees
  - `location2.longitude` — string · Longitude of the destination in decimal degrees
  - `location2.city` — string · City the destination resolves to
  - `location2.state` — string · State or region the destination resolves to
- `bearing` — number · Compass bearing in degrees (0-360) from location1 to location2 · (premium)
- `direction` — string · Cardinal direction: North, Northeast, East, Southeast, South, Southwest, West, Northwest · (premium)
- `estimatedDriveTime` — string · Rough driving time (e.g., 3h 45m) from the straight-line distance at 50 mph with a 1.3x road factor; null unless both points resolve to a US location and are within 3,000 miles · (premium)

## Sample response

```json
{
  "status": "ok",
  "error": null,
  "data": {
    "distanceMiles": 199.6804337234997,
    "distanceKm": 321.2535462758628,
    "location1": {
      "latitude": "36.728450",
      "longitude": "-119.53571",
      "city": "Sanger",
      "state": "California"
    },
    "location2": {
      "latitude": "34.044662",
      "longitude": "-118.24255",
      "city": "Los Angeles",
      "state": "California"
    },
    "bearing": 198,
    "direction": "South",
    "estimatedDriveTime": "5h 11m"
  }
}
```

## Use cases

- **Delivery Radius Verification** — Local couriers check mile distances between warehouse coordinates and customer dropoff points to confirm addresses fall within active delivery zones.
- **Road Trip Itinerary Planning** — When travelers add stops to a route, travel apps calculate kilometer distances between waypoints to tally total travel distance.
- **Real Estate Search Filtering** — Property portals measure distances from listed homes to city center coordinates so apartment hunters can filter rentals by commute proximity.
- **Fleet Dispatch Optimization** — Dispatchers compute coordinate distances between open service tickets and available technicians to assign the nearest field worker to incoming jobs.

## SDKs

- **npm** — `npm install @apiverve/distancecalculator` (https://www.npmjs.com/package/@apiverve/distancecalculator)
- **PyPI** — `pip install apiverve-distancecalculator` (https://pypi.org/project/apiverve-distancecalculator/)
- **NuGet** — `dotnet add package APIVerve.API.DistanceCalculator` (https://www.nuget.org/packages/APIVerve.API.DistanceCalculator)
- **Source** — https://github.com/apiverve/distancecalculator-api

## More

- Full reference: https://docs.apiverve.com/ref/distancecalculator
- Get an API key: https://dashboard.apiverve.com
- Full catalog: https://apiverve.com/marketplace
