conycom/laravel-distance-router

Calculate road distances using Google Maps or OpenRouteService with automatic caching.

Maintainers

Package info

github.com/conycom/laravel-distance-router

pkg:composer/conycom/laravel-distance-router

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-08-12 21:29 UTC

This package is auto-updated.

Last update: 2026-08-13 06:12:44 UTC


README

A smart routing and distance calculation package for Laravel. It calculates driving distances (round-trip) seamlessly falling back between OpenRouteService (ORS) and Google Maps, with automatic caching and Spanish Postal Code geocoding.

Run tests

Features

  • Multi-provider support (ORS or Google Maps)
  • Automatic coordinate resolution from Spanish Postal Codes (via Nominatim OpenStreetMap)
  • Aggressive caching (using Laravel's native Cache) to minimize API costs
  • Designed for logistics, ecommerce, and federated sports routing

Installation

composer require conycom/laravel-distance-router

Publish the configuration file:

php artisan vendor:publish --tag="distance-router-config"

Configuration

Set your preferred provider and API keys in your .env file:

DISTANCE_ROUTER_PROVIDER=ors # or 'google'
ORS_API_KEY=your-ors-api-key
GOOGLE_MAPS_API_KEY=your-google-maps-api-key

Usage

You can pass either coordinate arrays ['lat' => X, 'lon' => Y] or Spanish postal codes (as strings). The package will automatically geocode the postal codes and cache the result.

use Conycom\DistanceRouter\Facades\DistanceRouter;

// Using coordinates
$result = DistanceRouter::getRoundTripDistance(
    ['lat' => 40.4167, 'lon' => -3.7033], // Madrid
    ['lat' => 41.3851, 'lon' => 2.1734]   // Barcelona
);

// Using Spanish Postal Codes
$result = DistanceRouter::getRoundTripDistance('28001', '08001');

/*
$result returns:
[
    'success' => true,
    'km' => 1240.5,      // Total round-trip distance in KM
    'duration' => 36000, // Estimated driving duration in seconds
    'source' => 'ors'    // 'ors', 'google', or 'cache'
]
*/

License

The MIT License (MIT).