Measuring the Miles: Instant Proximity Insights with GeoDistance

measuring-the-miles-instant-proximity-insights-with-geodistance

Overview

GeoDistance calculates the straight‑line (as‑the‑crow‑flies) distance between two U.S. ZIP Codes by using each ZIP Code’s centroid. You can request results in miles, kilometers, or nautical miles—all via a single HTTP GET.

Key Business Use Cases

1. Logistics Planning & Route Optimization

Feed distance metrics into your routing engine or WMS to plan the most efficient delivery paths and reduce fuel costs.

2. Market Analysis & Catchment Areas

Define customer catchment radii around stores or service centers to inform expansion decisions and targeted marketing.

3. Dynamic Pricing & Service Eligibility

Adjust shipping fees, delivery schedules, or service availability based on customer proximity to your facilities.

Developer Spotlight: C# Code Snippet


// GeoDistance C# example
using System;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

namespace CDXGeoDataSample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var apiKey = Environment.GetEnvironmentVariable("CDX_GEO_KEY");
            var zip1   = "07869";
            var zip2   = "07840";
            var format = "json";
            var path   = $"/api/geodistance?key={apiKey}&zipcode1={zip1}&zipcode2={zip2}&format={format}";

            using var client = new HttpClient { BaseAddress = new Uri("https://geodata.cdxtech.com") };
            var resp         = await client.GetAsync(path);
            resp.EnsureSuccessStatusCode();

            var payload = await resp.Content.ReadAsStringAsync();
            var root    = JsonDocument.Parse(payload).RootElement;

            var result  = root.GetProperty("results")[0];
            var dist    = result.GetProperty("distance").GetDouble();
            var unit    = result.GetProperty("distanceUnit").GetString();

            Console.WriteLine($"Distance between {zip1} and {zip2}: {dist} {unit}");
        }
    }
}
  

Sample Response

{
  "service": "GeoDistance",
  "results": [{
    "coordinates": [
      { "zipCode": "07869", "latitude": 40.842115, "longitude": -74.58229 },
      { "zipCode": "07840", "latitude": 40.864954, "longitude": -74.822685 }
    ],
    "distance": 12.6614,
    "distanceUnit": "miles"
  }],
  "tokenCharge": 1
}
  

Getting Started

  1. Sign up for a free API key (100 tokens) at the CDXGeoData portal.
  2. Invoke GET /api/geodistance with key, zipcode1, zipcode2, and format.
  3. Parse the returned distance and distanceUnit to integrate proximity insights into your app.
Comments are closed