Zip Code Distance Endpoint

On this page, we'll dive into the zip code distance endpoint you can use to calculate distances between zip codes.


GET/v1/distance

Calculate Distances Between Zip Codes

This endpoint calculates the distance between a single zip code and one or more other zip codes. Codes from compare that cannot be found in our database are omitted from results instead of causing an error, so check for missing keys when processing the response.

Required attributes

  • Name
    code
    Type
    string
    Description

    The source zip code to calculate distances from. Example: 99501

  • Name
    compare
    Type
    string
    Description

    Comma-separated list of zip codes to compare distances to (max 100). Example: 90210,15106

  • Name
    country
    Type
    string
    Description

    Two letter country code. Example: us

Optional attributes

  • Name
    unit
    Type
    string
    Description

    Unit for distance calculation. Options: km, miles. Default: km. mi is accepted as an alias for miles.

Request

GET
/v1/distance
curl -G "https://api.zipcodestack.com/v1/distance?code=99501&compare=90210,15106&country=us&unit=km" \
    -H "apikey: YOUR-API-KEY"

Full Response

{
    "query": {
        "code": "99501",
        "compare": [
        "90210",
        "15106"
        ],
        "country": "us",
        "unit": "km"
    },
    "results": {
        "90210": 3754.89,
        "15106": 5115.42
    }
}