PHP code example of devshaded / nvdb-speed-limits

1. Go to this page and download the library: Download devshaded/nvdb-speed-limits 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/ */

    

devshaded / nvdb-speed-limits example snippets


return [
    'api' => [
        'base_url' => 'https://nvdbapiles-v3.atlas.vegvesen.no',
        'timeout' => 30,
        'headers' => [
            'accept' => 'application/vnd.vegvesen.nvdb-v3-rev1+json',
            'X-Client' => 'LaravelNvdbSpeedLimits/1.0',
        ],
    ],
    'search' => [
        'default_radius' => 0.0001, // ~11 meters
        'max_radius' => 0.005,      // ~550 meters
        'radius_multiplier' => 3,   // For expanding search
    ],
    'bounds' => [
        'latitude' => [57, 72],
        'longitude' => [4, 32],
    ],
];

use DevShaded\NvdbSpeedLimits\Facades\NvdbSpeedLimits;
// or
use DevShaded\NvdbSpeedLimits\NvdbSpeedLimits;

$result = NvdbSpeedLimits::getSpeedLimit(59.9139, 10.7522);

if ($result->found) {
    echo "Speed limit: " . $result->recommended['speed'] . " km/h";
} else {
    echo "No speed limit found.";
}

$result = NvdbSpeedLimits::getSpeedLimit(59.9139, 10.7522, 100); // 100 meters

$result = NvdbSpeedLimits::getSpeedLimitWithExpandedSearch(59.9139, 10.7522);

if ($result->found) {
    echo "Speed limit: " . $result->recommended['speed'] . " km/h";
}

$coordinates = [
    ['lat' => 59.9139, 'lng' => 10.7522],
    ['latitude' => 60.3913, 'longitude' => 5.3221],
    ['lat' => 61.1234, 'lng' => 11.5678],
];

$results = NvdbSpeedLimits::getSpeedLimitsForCoordinates($coordinates);

foreach ($results as $item) {
    if ($item['error']) {
        echo "Error for coordinate (" . json_encode($item['coordinate']) . "): " . $item['error'] . "\n";
    } else {
        echo "Speed limit at (" . $item['coordinate']['lat'] . ", " . $item['coordinate']['lng'] . "): " . $item['result']->recommended['speed'] . " km/h\n";
    }
}
bash
php artisan vendor:publish --tag="nvdb-speed-limits-config"