Skip to content

Conversation

@sylvesterdamgaard
Copy link

Summary

Add full Distance API support to the Node SDK, matching the PHP SDK implementation. This enables distance calculations between coordinates with type-safe enums and a flexible Coordinate class.

Changes

New Features

  • Coordinate class - Flexible coordinate input handling with validation

    • Accepts strings ("lat,lng" or "lat,lng,id"), arrays ([lat, lng]), or objects ({lat, lng, id})
    • Validates latitude (-90 to 90) and longitude (-180 to 180) ranges
    • Converts to string format for GET requests and object format for POST requests
  • distance() - Single origin to multiple destinations (GET /distance)

    • Supports all coordinate input formats
    • Options: mode, units, maxResults, maxDistance, minDistance, etc.
  • distanceMatrix() - Multiple origins × destinations (POST /distance-matrix)

    • Full matrix calculation support
    • Same filtering options as distance()
  • Async Job Methods for large calculations:

    • createDistanceMatrixJob() - Create background job
    • distanceMatrixJobStatus() - Check job status
    • distanceMatrixJobs() - List all jobs
    • getDistanceMatrixJobResults() - Get completed results
    • downloadDistanceMatrixJob() - Download to file
    • deleteDistanceMatrixJob() - Delete job
  • Enhanced geocode()/reverse() - Optional distance parameters to calculate distances to destinations

New Types & Enums

  • DistanceMode: straightline, driving, haversine
  • DistanceUnits: miles, km
  • DistanceOrderBy: distance, duration
  • DistanceSortOrder: asc, desc
  • Full TypeScript definitions for all response types

Other Changes

  • Default API version updated to v1.9
  • Package version bumped to 1.12.0
  • Added "distance" and "distance-matrix" to package keywords

Test Plan

  • Coordinate class unit tests (18 tests)
    • Creation from numbers, strings, arrays, objects
    • Validation of lat/lng ranges
    • toString() and toObject() conversion
  • Enum value tests (4 tests)
  • Integration tests with test API server (15 tests)
    • Basic distance calculation
    • Coordinate objects and array formats
    • Driving mode with duration
    • Kilometers unit
    • Max results filtering
    • Distance matrix (POST)
    • Geocode/reverse with distance
    • Job creation, status, and deletion

Add full Distance API support matching the PHP SDK implementation:

- Add Coordinate class for flexible coordinate input handling
- Add distance() method for single origin to multiple destinations (GET)
- Add distanceMatrix() method for multiple origins × destinations (POST)
- Add async job methods: createDistanceMatrixJob, distanceMatrixJobStatus,
  distanceMatrixJobs, getDistanceMatrixJobResults, downloadDistanceMatrixJob,
  deleteDistanceMatrixJob
- Enhance geocode() and reverse() with optional distance parameters
- Add TypeScript definitions for all new types and methods
- Add enums: DistanceMode, DistanceUnits, DistanceOrderBy, DistanceSortOrder
- Update default API version to v1.9
- Add comprehensive test suite for Distance API
Match the comprehensive documentation style from the PHP library:

- Coordinate format with custom IDs
- Distance mode and units with enums
- Add distance to geocoding requests
- Single origin to multiple destinations
- Distance matrix calculations
- Nearest mode (find closest destinations)
- Async distance matrix jobs
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