PHP code example of jansuchanek / ndistance

1. Go to this page and download the library: Download jansuchanek/ndistance library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jansuchanek / ndistance example snippets


use NDistance\DistanceCalculator;

$calc = new DistanceCalculator(
    userAgent: 'MyApp/1.0',
    defaultCountry: 'cz',
);

// Geocode address
$coords = $calc->geocode('Brno, Česko');
// ['lat' => 49.19, 'lng' => 16.61]

// Driving distance between coordinates
$route = $calc->drivingDistance(50.08, 14.42, 49.19, 16.61);
// ['distance' => 205.3, 'duration' => 125]  (km, minutes)

// Check delivery range
$result = $calc->checkDistance(50.08, 14.42, 'Brno', 250.0);
// ['ok' => true, 'distance' => 205.3, 'duration' => 125, ...]