Skip to content

Conversation

@sylvesterdamgaard
Copy link

Summary

Add comprehensive Distance API support to the Geocodio PHP SDK, enabling distance calculations between coordinates with type-safe enums and a new Coordinate DTO class.

Changes

New Enums

  • DistanceMode - Straightline, Driving, Haversine (backward compat alias)
  • DistanceUnits - Miles, Km
  • DistanceOrderBy - Distance, Duration
  • DistanceSortOrder - Asc, Desc

New Coordinate DTO

  • Type-safe Coordinate readonly class with lat/lng validation
  • Supports optional ID for tracking origins/destinations in responses
  • Converts between string format (lat,lng,id) and object format for API

New Distance Methods

  • distance() - Calculate from single origin to multiple destinations (GET)
  • distanceMatrix() - Calculate full matrix: multiple origins × destinations (POST)

Async Distance Matrix Jobs

  • createDistanceMatrixJob() - Create background processing job
  • distanceMatrixJobStatus() - Check job status
  • distanceMatrixJobs() - List all jobs (paginated)
  • getDistanceMatrixJobResults() - Get parsed JSON results
  • downloadDistanceMatrixJob() - Download results to file
  • deleteDistanceMatrixJob() - Delete a job

Enhanced Geocoding

  • geocode() now accepts destinations parameter for distance calculations
  • reverse() now accepts destinations parameter for distance calculations
  • Full filtering support: maxResults, maxDistance, maxDuration, minDistance, minDuration
  • Sorting options: orderBy (distance/duration), sortOrder (asc/desc)

Documentation

  • Comprehensive README documentation for all distance features
  • Reorganized TOC: Distance section moved after Uploading Lists

Test Plan

  • Unit tests pass (ArchTest, ListTest, TimeoutConfigurationTest)
  • Manual testing with local dev API
    • Basic distance with Coordinate objects
    • Distance with driving mode
    • Distance matrix with custom IDs
    • Async distance matrix job creation, status, results, download, delete
    • Geocode with distance destinations
    • Reverse geocode with distance destinations
  • Integration tests (require GEOCODIO_API_KEY)

- Add DistanceMode enum (Straightline, Driving, Haversine)
- Add DistanceUnits enum (Miles, Km)
- Add DistanceOrderBy enum (Distance, Duration)
- Add DistanceSortOrder enum (Asc, Desc)
- Add Coordinate readonly class for type-safe coordinate handling
  with lat/lng validation and optional ID support
Add distance calculation methods:
- distance() - single origin to multiple destinations (GET)
- distanceMatrix() - multiple origins × destinations (POST)

Add async distance matrix job methods:
- createDistanceMatrixJob() - create background job
- distanceMatrixJobStatus() - check job status
- distanceMatrixJobs() - list all jobs
- getDistanceMatrixJobResults() - get parsed results
- downloadDistanceMatrixJob() - download to file
- deleteDistanceMatrixJob() - delete job

Add distance support to geocoding:
- geocode() with destinations parameter
- reverse() with destinations parameter

Features:
- Type-safe enums for mode, units, orderBy, sortOrder
- Coordinate DTO with object format for POST requests
- Haversine→straightline mapping for backward compat
- Filtering: maxResults, maxDistance, maxDuration, etc.
- Custom IDs for tracking origins/destinations
Add comprehensive test coverage for:
- GET /distance endpoint with various coordinate formats
- POST /distance matrix endpoint
- Nearest mode with filtering options
- Haversine mode backward compatibility
- Custom ID support for coordinates
Document all distance features:
- Coordinate format with custom IDs
- Distance mode and units enums
- Add distance to geocode/reverse requests
- Single origin to multiple destinations
- Distance matrix (multiple origins × destinations)
- Nearest mode filtering options
- Async distance matrix jobs

Reorganize TOC: move distance after uploading lists
Prevents misidentifying invalid coordinates with range validation:
- Latitude must be between -90 and 90
- Longitude must be between -180 and 180

This catches obvious non-coordinates like '123, 456' while accepting
valid integer coordinates like '38,-77'.
- distanceMatrix() now uses POST /distance-matrix
- Async job endpoints moved from /distance-matrix to /distance-jobs
- Remove invalid @var annotations on constants
- Change Response to ResponseInterface for proper PSR-7 compliance
- Add never return type to handleException() method
- Remove Haversine from enum documentation
- Use named parameters in geocode example
- Update billing note to reference pricing page
The API supports both 'haversine' and 'straightline' mode values directly,
so the SDK-side conversion is redundant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants