I'd like to change the Latitude and Longitude which make up a route.

For example I have point A and point B the routing machine will create the coordinates and generate the details for the itinerary in between those points, creating a route.

I'd like to change all the coordinates/points in-between point A and point B, thus creating a custom route. And creating a itinerary based on it.

This is the how the L.Routing.OSRMv1.extend can be created with a customCallback, I just don't know how to integrate it....

const customCallback = (callback) => (context, error, routes) => {
  for (const route of routes) {
    route.coordinates = [...route.coordinates, L.latLng(12.33, 49.6753)];

  callback(context, error, routes);

const router = L.Routing.OSRMv1.extend({
  initialize: function (options) {
    L.Routing.OSRMv1.prototype.initialize.call(this, options);

  route: function (waypoints, callback, context, options) {
    const originalCallback = options.callback;
    L.Routing.OSRMv1.prototype.route.call(waypoints, customCallback(originalCallback), this, options);

The Routing control:

const routingControl = L.Routing.control({
  addWaypoints: false,
  collapsible: true,
  createMarker: function (i, wp, nWps) {
  draggableWaypoints: true,
  fitSelectedRoutes: true,
  geocoder: L.Control.Geocoder.nominatim(),
  lineOptions: {...},
  show: true,
  showAlternatives: false,


Executing router yields:

TypeError: Cannot convert undefined or null to object

Anyone have an idea how to integrate your own coordinates in a route?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.