[GIS] How to show directions on the map

directionleafletmapbox

I am using Mapbox, Leaflet.
Via Mapbox Walking directions I create directions and save origin and destination markers coordinates; Then I want to show this created direction. So I do following:

<script>
        var start = JSON.parse($('#start_field').val());
        var finish = JSON.parse($('#finish_field').val());
        L.mapbox.accessToken = 'qwerty';
        var map = L.mapbox.map('map', 'mapbox.streets', {
            zoomControl: false
        }).setView([42.8580536, 74.6224754], 12);
        L.Routing.control({
            waypoints: [
                L.latLng(start.lat, start.lng),
                L.latLng(finish.lat, finish.lng)
            ]
        }).addTo(map);

        var start_marker = L.marker([start.lat, start.lng], {
            draggable: false
        }).addTo(map);

        var finish_marker = L.marker([finish.lat, finish.lng], {
            draggable: false
        }).addTo(map);
    </script>

But I have an error:

Uncaught TypeError: Cannot read property 'control' of undefined

Best Answer

Somehow L.Routing doesn't exist. Are you using Leaflet Routing Machine? Make sure you're loading the script: <script src="leaflet-routing-machine.js">.

Related Question