Skip to main content

Routing API Documentation

Complete documentation for all routing and navigation services.


Transportation Profiles

All routing methods support these profiles:

ProfileDescriptionUse Case
carDriving routes (default)Car navigation, delivery
footWalking routesPedestrian navigation
motorcycleMotorcycle routesBike delivery, riders
bikeBicycle routesCycling navigation

Route Overview

Get a simple route between multiple points.

Method

Barikoi::routeOverview(array $points, array $options = [])

Parameters

ParameterTypeRequiredDescription
pointsarrayYesArray of coordinate objects (min 2)
optionsarrayNoRouting options

Point Format

[
'longitude' => float,
'latitude' => float
]

Options

OptionTypeDefaultDescription
profilestring'car'Transportation mode. Allowed values: car or foot only
geometriesstring'polyline'Returned route geometry format (influences overview and per step). Expected values: polyline, polyline6, or geojson

Usage

use Barikoi\BarikoiApis\Facades\Barikoi;
use Barikoi\BarikoiApis\Exceptions\BarikoiValidationException;

try {
$points = [
['longitude' => 90.3572, 'latitude' => 23.8067],
['longitude' => 90.3680, 'latitude' => 23.8100],
];

// Car route (returns stdClass object)
$route = Barikoi::routeOverview($points);

// Walking route
$walkingRoute = Barikoi::routeOverview($points, [
'profile' => 'foot'
]);

// Access response (object / stdClass)
$thisRoute = $route->routes[0] ?? null;
if ($thisRoute) {
$distance = $thisRoute->distance; // in meters
$duration = $thisRoute->duration; // in seconds
}

} catch (BarikoiValidationException $e) {
echo "Invalid route: " . $e->getMessage();
}

Response

{
"code": "Ok",
"routes": [
{
"distance": 1234, // meters
"duration": 456, // seconds
"geometry": "..." // encoded polyline (polyline6 when requested)
}
// ... possibly more routes
]
}

Conditions

  • Minimum 2 points required
  • Maximum 50 waypoints
  • Points must be valid coordinates

Error Handling

Error CodeExceptionCauseSolution
400BarikoiValidationExceptionLess than 2 pointsProvide origin and destination
400BarikoiValidationExceptionInvalid profileUse only: car or foot
400BarikoiValidationExceptionInvalid coordinatesCheck lat/lng values
404BarikoiApiExceptionNo route foundPoints may be too far or unreachable

Calculate Route

Calculate detailed route with navigation instructions using the routing API (returns object with trip).

Method

Barikoi::calculateRoute(array $startDestination, array $options = [])

Parameters

ParameterTypeRequiredDescription
startDestinationarrayYesArray containing start and destination keys, each with longitude and latitude (see format below)
optionsarrayNoRouting options (type, profile, country_code)

Start/Destination Format

The startDestination parameter must be an array with the following structure:

[
'start' => [
'longitude' => float, // Start point longitude (-180 to 180)
'latitude' => float // Start point latitude (-90 to 90)
],
'destination' => [
'longitude' => float, // Destination longitude (-180 to 180)
'latitude' => float // Destination latitude (-90 to 90)
]
]

Validation:

  • Both start and destination keys are required
  • Each must contain longitude and latitude keys
  • Coordinates must be numeric
  • Latitude must be between -90 and 90
  • Longitude must be between -180 and 180

Options

OptionTypeDefaultDescription
typestring'vh'Routing engine type: vh (motorcycle only) or gh (all profiles)
profilestring'motorcycle'Transport profile: motorcycle, car, or bike
country_codestring'bgd'ISO Alpha-3 country code

Usage

use Barikoi\BarikoiApis\Facades\Barikoi;

// Motorcycle route with 'vh' type
$route = Barikoi::calculateRoute([
'start' => [
'longitude' => 90.36558776260725,
'latitude' => 23.791645065364126
],
'destination' => [
'longitude' => 90.3676300089066,
'latitude' => 23.784715477921843
],
], [
'type' => 'vh',
'profile' => 'motorcycle'
]);

// Car route with 'gh' type
$carRoute = Barikoi::calculateRoute([
'start' => ['longitude' => 90.365588, 'latitude' => 23.791645],
'destination' => ['longitude' => 90.367630, 'latitude' => 23.784715],
], [
'type' => 'gh',
'profile' => 'car'
]);

Response

Returns navigation route with trip:

{
"trip": {
"locations": [
{ "type": "break", "lat": 23.791645, "lon": 90.365587 },
{ "type": "break", "lat": 23.784715, "lon": 90.36763 }
],
"legs": [
{
"maneuvers": [
{
"instruction": "Drive north.",
"time": 1.011,
"length": 0.006
}
],
"summary": {
"length": 2.34,
"time": 320
}
}
]
}
}

Validation

The start/destination format includes automatic validation:

  • Validates that start and destination keys exist
  • Validates that both contain longitude and latitude keys
  • Validates that coordinates are numeric
  • Validates coordinate ranges (lat: -90 to 90, lng: -180 to 180)

Error Handling

ErrorExceptionCauseSolution
Invalid formatBarikoiValidationExceptionMissing start or destination keysProvide both keys
Invalid coordinatesBarikoiValidationExceptionMissing or invalid lat/lngCheck coordinate format
Invalid rangeBarikoiValidationExceptionCoordinates out of rangeUse valid lat (-90 to 90) and lng (-180 to 180)
Invalid type/profileObject with status: 400Unsupported combinationUse valid type/profile combination