Route and schedules optimization

How to use Geoapify Route Planner API to optimize route and schedules of a service company workers

by Geoapify

HTML

<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.css">
<script src="https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.js"></script>
<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: [5.59132, 45.36671],
  zoom: 14,
  style: `https://maps.geoapify.com/v1/styles/klokantech-basic/style.json?apiKey=${myAPIKey}`,
});
map.addControl(new maplibregl.NavigationControl());

// this object describes the task
const serviceJobsOptimizationInput = {
  "mode": "drive",
  "agents": [{
      "start_location": [
        5.586790932250917,
        45.36538915
      ],
      "end_location": [
        5.586790932250917,
        45.36538915
      ],
      "time_windows": [
        [
          3600,
          10800
        ]
      ],
      "capabilities": [
        "Cooling system tester",
        "Motor locking tool"
      ]
    },
    {
      "start_location": [
        5.589290483511979,
        45.36931755
      ],
      "end_location": [
        5.589290483511979,
        45.36931755
      ],
      "time_windows": [
        [
          3600,
          10800
        ]
      ],
      "capabilities": [
        "Welding machine",
        "Motor locking tool"
      ]
    },
    {
      "start_location": [
        5.590490376922535,
        45.36242105
      ],
      "end_location": [
        5.590490376922535,
        45.36242105
      ],
      "time_windows": [
        [
          0,
          7200
        ]
      ],
      "capabilities": [
        "Cooling system tester",
        "Motor locking tool"
      ]
    },
    {
      "start_location": [
        5.590442806010234,
        45.36164335
      ],
      "end_location": [
        5.590442806010234,
        45.36164335
      ],
      "time_windows": [
        [
          0,
          7200
        ]
      ],
      "capabilities": [
        "Welding machine",
        "Motor locking tool"
      ]
    },
    {
      "start_location": [
       ...