Postal Address Verification API
GetZipCodesWithinDistance
The GetZipCodesWithinDistance
method returns all ZIP Codes within a radius around a given latitude/longitude geolocation.
Endpoint
GET:https://pav3.esendex.us/PavService.svc/GetZipCodesWithinDistance?Latitude={LATITUDE}&Longitude={LONGITUDE}&Radius={RADIUS}&LicenseKey={LICENSEKEY}
Syntax
GetZipCodesWithinDistance(Latitude, Longitude, Radius, LicenseKey)
Request Parameters
Parameter Name | Description | Data Type | Required | Sample Value |
---|---|---|---|---|
Latitude | Latitude coordinate from -179.2311 to 179.8597. | String | True | 36.763075 |
Longitude | Longitude coordinate from 17.8315 to 71.4411. | String | True | -76.258473 |
Radius | Radius in miles. (The maximum is 50.) | String | True | 2.1 |
LicenseKey | Your license key. | String | True | 00000000-0000-0000-0000-000000000000 |
Response
Returns: ZipCodesResponse
object
Code Samples
You can use any programming language you want with our API, as long as it can make a REST or SOAP call. Here are examples for some of the most common platforms.
C#
// https://pav3.esendex.us/PavService.svc?wsdl was added as a Service Reference and given the name WSDL
using System;
using WSDL;
var config = PavServiceClient.EndpointConfiguration.pavws_secure;
var client = new PavServiceClient(config);
var latitude = "36.761560";
var longitude = "-76.259964";
var radius = "5";
var licenseKey = "YOUR_LICENSE_KEY";
var response = await client.GetZipCodesWithinDistanceAsync(latitude, longitude, radius, licenseKey);
var returnCodeDescription = response.ReturnCode switch
{
0 => "Success",
1 => "Invalid input",
2 => "Invalid license key",
3 => "Returned 0 ZIP Codes (no matches)",
4 => "Outside of latitude/longitude range",
_ => "Unknown return code"
};
Console.WriteLine($"Return Code: {response.ReturnCode} - {returnCodeDescription}");
if (response.ZipCodes is not null)
{
foreach (var zip in response.ZipCodes)
{
Console.WriteLine($"ZIP Code: {zip}");
}
}
Console.ReadLine();
JavaScript
const params = new URLSearchParams({
'Latitude': '36.763075',
'Longitude': '-76.258473',
'Radius': '5',
'LicenseKey': '00000000-0000-0000-0000-000000000000'
});
const url = 'https://pav3.esendex.us/PavService.svc/GetZipCodesWithinDistance?' + params.toString();
const options = {
headers: {
'Accept': 'application/json'
}
};
const response = await fetch(url, options);
const json = await response.json();
console.log(json);
JSON Response
{
"ReturnCode": 0,
"ZipCodes": [
"23320",
"23325",
"23324"
]
}
PHP with cURL
<?php
$client = new SoapClient('https://pav3.esendex.us/PavService.svc?wsdl');
$param = array(
'Latitude' => '36.761560'
, 'Longitude' => '-76.259964'
, 'Radius' => '5'
, 'LicenseKey' => 'YOUR LICENSE KEY'
);
$result = $client->GetZipCodesWithinDistance($param);
echo "<pre>";
print_r($result);
echo "</pre>";
?>
Python
import httpx
headers = {"Accept": "application/json"}
url = "https://pav3.esendex.us/PavService.svc/GetZipCodesWithinDistance"
request = {
"Latitude": "36.763075",
"Longitude": "-76.258473",
"Radius": "5",
"LicenseKey": "00000000-0000-0000-0000-000000000000",
}
with httpx.Client(headers=headers) as client:
response = client.get(url=url, params=request)
response.raise_for_status()
print(response.json())
Ruby
require 'json'
require 'net/http'
headers = { Accept: 'application/json', 'Content-Type': 'application/json' }
uri = URI('https://pav3.esendex.us/PavService.svc/GetZipCodesWithinDistance')
params = {
'Latitude': '36.763075',
'Longitude': '-76.258473',
'Radius': '5',
'LicenseKey': '00000000-0000-0000-0000-000000000000'
}
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get(uri, headers)
raise response.message if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)
puts JSON.parse(response)
XML Response
<ZipCodesResponse xmlns="pav3.esendex.us" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ReturnCode>0</ReturnCode>
<ZipCodes xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:string>23320</a:string>
<a:string>23325</a:string>
<a:string>23324</a:string>
</ZipCodes>
</ZipCodesResponse>
Let’s start sending, together.