Circle the Community: GeoRadiusCanadian’s Postal Code Proximity Search

circle-the-community-georadiuscanadians-postal-code-proximity-search

Overview

GeoRadiusCanadian returns all Canadian postal codes within a specified radius of a given postal code or latitude/longitude. Simply supply your API key, a starting postal code (or lat/lon), the radius in kilometers or miles, and your preferred output format (JSON, XML or CSV), and receive a sorted list of nearby codes along with their distances.

Key Business Use Cases

1. Service‑Area Determination

Define and visualize delivery or support zones around your locations by generating a list of all postal codes within your service radius—ideal for logistics and field operations planning.

2. Proximity‑Based Marketing

Target promotions, coupons, or outreach campaigns to households within a precise radius of your storefronts or events, using up‑to‑date postal code clusters.

3. Emergency & Community Planning

Identify neighborhoods and infrastructure at risk within a disaster radius—streamline outreach, resource allocation, and evacuation planning.

Developer Spotlight: C# Code Snippet


// GeoRadiusCanadian 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 postalCode = "M5V3L9";       // Toronto downtown
            var radius     = 15;             // kilometers
            var unit       = "km";
            var format     = "json";
            var url        = $"https://geodata.cdxtech.com/api/georadiuscanadian?key={apiKey}"
                            + $"&postalcode={postalCode}"
                            + $"&radius={radius}&unit={unit}&format={format}";

            using var client   = new HttpClient();
            var response       = await client.GetAsync(url);
            response.EnsureSuccessStatusCode();

            var json    = await response.Content.ReadAsStringAsync();
            var results = JsonDocument.Parse(json)
                                      .RootElement
                                      .GetProperty("results");

            Console.WriteLine($"Postal codes within {radius} {unit} of {postalCode}:");
            foreach (var item in results.EnumerateArray())
            {
                var code = item.GetProperty("postalCode").GetString();
                var dist = item.GetProperty("distance").GetDouble();
                Console.WriteLine($"  {code}: {dist} {unit}");
            }
        }
    }
}

Sample Response

{
  "service": "GeoRadiusCanadian",
  "results": [
    { "postalCode": "M5V3L9", "latitude": 43.6435, "longitude": -79.3851, "distance": 0.0 },
    { "postalCode": "M5V2T6", "latitude": 43.6452, "longitude": -79.3838, "distance": 0.3 },
    { "postalCode": "M5V1K1", "latitude": 43.6419, "longitude": -79.3926, "distance": 0.8 },
    { "postalCode": "M5V3K2", "latitude": 43.6448, "longitude": -79.3820, "distance": 0.4 }
  ],
  "tokenCharge": 2
}

Getting Started

  1. Sign up for your free CDXGeoData account and retrieve your API key.
  2. Invoke GET /api/georadiuscanadian with key, postalcode (or latitude & longitude), radius, unit, and format.
  3. Parse the results array to integrate nearby postal codes and distance metrics into your application.
Comments are closed