Bus routes optimization

How to use Geoapify Route Planner API to optimize school and shuttle buses routes and carpooling

by Geoapify

HTML

<script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/maplibre-gl.css">
<div id="my-map"></div>

CSS

body {
      margin: 0;
      padding: 0;
    }

    #my-map {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 100%;
    }

JavaScript

// The API Key provided is restricted to JSFiddle website
// Get your own API Key on https://myprojects.geoapify.com
const myAPIKey = "6dc7fb95a3b246cfa0f3bcef5ce9ed9a";

// create a map object
const map = new maplibregl.Map({
  container: 'my-map',
  center: [7.438684130809055,
        46.95097255],
  zoom: 12,
  style: `https://maps.geoapify.com/v1/styles/klokantech-basic/style.json?apiKey=${myAPIKey}`,
});
map.addControl(new maplibregl.NavigationControl());

// this object describes the task
const busRouteOptimizationInput = {
  "mode": "drive",
  "agents": [
    {
      "start_location": [
        7.4474023,
        46.9467234
      ],
      "end_location": [
        7.438684130809055,
        46.95097255
      ],
      "pickup_capacity": 4
    },
    {
      "start_location": [
        7.4378570072965395,
        46.9486723
      ],
      "end_location": [
        7.438684130809055,
        46.95097255
      ],
      "pickup_capacity": 4
    },
    {
      "start_location": [
        7.4527263,
        46.9491169
      ],
      "end_location": [
        7.438684130809055,
        46.95097255
      ],
      "pickup_capacity": 4
    },
    {
      "start_location": [
        7.465467108707118,
        46.942533
      ],
      "end_location": [
        7.438684130809055,
        46.95097255
      ],
      "pickup_capacity": 7
    },
    {
      "start_location": [
        7.462132898387589,
        46.94558515
      ],
      "end_location": [
        7.438684130809055,
        46.95097255
      ],
      "pickup_capacity": 4
    }
  ],
  "jobs": [
    {
      "location": [
        7.450493219453888,
        46.9399672
      ],
      "duration": 300,
      "pickup_amount": 1
    },
    {
      "location": [
        7.456512380644636,
        46.940145599999994
      ],
      "duration": 300,
      "pickup_amount": 1
    },
    {
      "location": [
        7.455119358248906,
        46.94004565
      ],
      "duration": 300,
      "pickup_amount": 1
    },
   ...