API Freaks logoAPI Freaks logo
CTRL+K

    APIs

  • Pricing
  • Resources
  • Tools

  • Contact us
CTRL+K
Sign InGet Started For Free
  • Overview
  • Documentation
  • How to Guides
  • Pricing
  • APIFreaks
  • Organization and Teams
  • Credits Usage API
  • IP Geolocation Lookup
  • Bulk IP Geolocation Lookup
  • Domain WHOIS Lookup
  • IP WHOIS Lookup
  • ASN Lookup
  • Domain WHOIS Historical Lookup
  • Domain WHOIS Reverse Lookup
  • Bulk Domain WHOIS Lookup
  • DNS Lookup
  • Historical DNS Lookup
  • Reverse DNS Lookup
  • Bulk DNS Lookup
  • Email Checker API
  • SSL Certificate Lookup
  • Domain Availability
  • Bulk Domain Availability API
  • Website Screenshot
  • Bulk Screenshot
  • Currencies Exchange Rates
  • Currency Converter
  • Currency Time Series
  • Currency Fluctuation
  • Geolocalized Currency Converter
  • Live Commodity Prices
  • Commodity Historical Prices
  • Commodity Fluctuation
  • Commodity Time Series
  • IBAN Validation
  • ZIP Code API
  • ZIP Code Search Inside Radius
  • ZIP Code Distance API
  • ZIP Code Search By City
  • Live Weather API
  • Weather Forecast API
  • Historical Weather API
  • Air Quality API
  • Marine Weather API
  • Flood Forecast API
  • Timezone Lookup
  • Timezone Converter
  • User Agent Parser
  • Bulk User Agent Parser
  • Astronomy API

ZIP Code Distance API - Calculate Distance Between ZIP Codes

ZIP Code Distance API is a quick solution to calculate straight-line distance (as-the-crow-flies), not the drive distance, between ZIP codes and postal codes. You can use this API in two ways:

  • Calculate distance from a base point to a list of target ZIP codes or postal codes. The base point can be a ZIP code, a postal code or a set of location coordinates (latitude & longitude). And, the list of target ZIP codes or postal codes from the same country as the base point.
  • Calculate distance between all the possible pairs of ZIP codes in a list and filter all the pairs that lie within an upper threshold on distance between them.

You can also configure the distance measuring unit to return the calculated distance value per your need. Supported distance measuring units are `mi` (mile), `km` (kilometer), `m` (meter), `ft` (feet), `yd` (yard), `in` (inch). But, ZIP Code Distance API uses `km` (kilometer) as default distance measuring unit.

ZIP Code Distance API has vast usage in businesses like to:

  • plan efficient delivery routes
  • Service Area: define service areas for your field teams
  • measure ETA for delivery
  • calculate shipping charges
  • manage logistics
  • emergency response in disaster management systems
  • define service area
  • find nearest services
10K Free Credits, No Credit Card Required

Features

ZIP Code or Postal Code as Base

You can use a ZIP code or a postal code at the base point, to calculate distance to your provided list of ZIP codes or postal code.

Location (Latitude & Longitude) as Base

You can also select a set of location coordinates (latitude, longitude) as the base to calculate distance to the provided list of ZIPs.

Bulk Comparison

ZIP Code Distance API can compare up to 100 ZIP codes or postal codes at a time in both modes. When pairing up 100 ZIP codes, it'll make up to 4950 pairs.

Configure Distance Measuring Unit

ZIP Code Distance API allows to convert distance between ZIP codes in a wide range of distance measuring units per your need. Allowed distance measuring units are `mi` (miles), `km` (kilometers), `m` (meters), `ft` (feets), `yd` (yards), `in` (inches). Though, `km` (kilometer) is the default unit.

Documentation

ZIP Code Distance API

API Endpoint

POST

https://api.apifreaks.com/v1.0/zipcode/distance

Test
LANGUAGE
Python
PHP
Java
Node
Ruby
JavaScript
C#
$ pip install requests

API Request

To use ZIP Code Distance endpoint, you can include the following fields in the JSON body:

ParameterRequiredTypeDefaultDescription
compareYesArray-List of ZIP or postal codes to calculate distance from the base point. All codes must exist in the same 'country'.
codeNoString-Base ZIP or postal code from which distances will be calculated. Must be provided together with 'country'.
countryNoString-Country where the ZIP/postal codes exist. Must be in ISO 3166-1 alpha-2 format. Must be provided together with 'code'.
latNoNumber-Base latitude coordinate from which distances will be calculated. Must be provided together with 'long'.
longNoNumber-Base longitude coordinate from which distances will be calculated. Must be provided together with 'lat'.
unitNoStringkmDistance measuring unit. Allowed values: 'km', 'mi', 'yd', 'm', 'ft', 'in'.

You must provide either a pair of lat and long or a combination of code and country as the required fields to specify the origin location. If both lat/long and code/country are provided in the request, the code and country combination will take precedence.

ZIP Code Distance Match API

API Endpoint

POST

https://api.apifreaks.com/v1.0/zipcode/distance/match

Test
LANGUAGE
Python
PHP
Java
Node
Ruby
JavaScript
C#
$ pip install requests

API Request

To use ZIP Code Distance Match endpoint, you can include the following fields in the JSON body:

ParameterRequiredTypeDefaultDescription
codesYesArray-List of ZIP or postal codes to find pairs within the specified distance. All codes must exist in the same country.
countryYesString-Country where the ZIP/postal codes exist. Must be in ISO 3166-1 alpha-2 format.
distanceNoNumber100Upper threshold distance value. All pairs of ZIP codes within this distance will be returned.
unitNoStringkmDistance measuring unit. Allowed values: 'km', 'mi', 'yd', 'm', 'ft', 'in'.

API Response

For a comprehensive view of the API response structure and detailed field descriptions, explore the interactive Response Table. For ZIP Code distance API click here and for ZIP Code Distance Match API click here.

HTTP Status Codes

HTTP StatusReasons
400
(1) A maximum of 100 postal/zip codes can be processed per request. (2) The provided unit symbol is invalid. Please refer to the documentation for supported units. (3) Only ISO 3166-1 alpha-2 country codes are supported. (4) Latitude must be between -90 and 90. (5) Longitude must be between -180 and 180.
404
(1) None of the provided postal/zip codes were found in our database.

How-To-Guides

Calculate Distance from A Location Coordinates to a List of ZIP Codes

You can use ZIP Codes Distance API to find distance to a list of ZIP codes or postal codes from any location point. All you need to provide is a list of ZIP codes or postal codes, a location coordinates and the country where they exist to calculate distance using ZIP Codes Distance API.

Pass all these parameters in the JSON body: lat (latitude), long (longitude), compare (array of ZIP/postal codes), and country (ISO 3166-1 alpha-2 code).

Let’s find the distance to E1 0AZ, HD1 1AB, OX1 1PU postcodes from location (lat: 51.5132336, long: -0.2273734) in the United Kingdom. Here is a curl request to do that:

curl -s -X POST "https://api.apifreaks.com/v1.0/zipcode/distance?apiKey=API-KEY" \ -H "Content-Type: application/json" \ -d '{ "lat": 51.5132336, "long": -0.2273734, "compare": ["E1 0AZ", "HD1 1AB", "OX1 1PU"], "country": "GB" }'
# Response { "result_count": 3, "results": [ { "code": "E1 0AZ", "distance": 11.977 }, { "code": "HD1 1AB", "distance": 259.566 }, { "code": "OX1 1PU", "distance": 76.004 } ] }

All the distances in the above response are measured in kilometers (km), the default distance measuring unit. But, you can specify your choice of unit.

Convert JSON Response to XML

ZIP Codes Distance API can respond in JSON or XML formats for all requests. But, it responds in JSON format by default. Pass format=xml URL parameter along with your request to convert the API response in XML format. Here is a curl request to do that:

curl -s -X POST "https://api.apifreaks.com/v1.0/zipcode/distance?format=xml&apiKey=API-KEY" \ -H "Content-Type: application/json" \ -d '{ "lat": 51.5132336, "long": -0.2273734, "compare": ["E1 0AZ", "HD1 1AB", "OX1 1PU"], "country": "GB" }'
# Response <CodeDistance> <result_count>3</result_count> <results> <code_distance> <code>E1 0AZ</code> <distance>11.977</distance> </code_distance> <code_distance> <code>HD1 1AB</code> <distance>259.566</distance> </code_distance> <code_distance> <code>OX1 1PU</code> <distance>76.004</distance> </code_distance> </results> </CodeDistance>

Find all Pairs of ZIP Codes within a Specific Distance

Given a list of ZIP codes, their country and an upper threshold on distance between them, you can find all pairs of ZIP codes in the list that are within the range of specified distance.

Suppose that you‘ve 5 US ZIP codes `71149`, `56517`, `54510`, `51549` and `10009`. Lets find out all ZIP codes pairs that are within 1000 miles from each other. Here is a curl request to do that:

curl -s -X POST "https://api.apifreaks.com/v1.0/zipcode/distance/match?apiKey=API-KEY" \ -H "Content-Type: application/json" \ -d '{ "codes": ["71149", "56517", "54510", "51549", "10009"], "country": "US", "distance": 1000, "unit": "mi" }'
# Response { "result_count": 2, "results": [{ "code_1": "56517", "code_2": "51549", "distance": 442.561 }, { "code_1": "71149", "code_2": "51549", "distance": 605.837 }] }

The above response includes all the ZIP codes that up to 1000 miles apart.

Pricing

To use the ZIP Code Distance and Distance Match APIs, API credits are required. Charges apply only for successful queries, defined by a 2xx status code. If a request results in a 4xx or 5xx status code, no credits will be deducted, and any credits already charged will be refunded.

  • ZIP Code Distance API: For each successful lookup, 5 credit will be charged.
  • ZIP Code Distance Match API: For each successful lookup, 5 credit will be charged.

Price Estimation Calculator

Ready to get started?

Sign Up for Free

APIFreaks

API Catalog

  • Geolocation APIs
  • WHOIS APIs
  • DNS APIs
  • Email Validation APIs
  • SSL APIs
  • Domain APIs
  • Screenshot APIs
  • Currency APIs
  • Commodity APIs
  • Financial APIs
  • ZIP Code APIs
  • Weather APIs
  • Timezone APIs
  • User Agent APIs
  • Other APIs

Tools Catalog

  • Code Formatters
  • Data & Query Tools
  • Text Tools
  • Email Utilities
  • DNS Tools
  • Viewers
  • Converters
  • PDF Tools

Docs

  • APIs
  • Swagger Docs

Pricing & Accounts

  • Pricing
  • Sign up
  • Sign In

Company

  • About Us
  • Resources
  • Terms
  • Privacy

Copyright © 2025

Made in Pakistan