1

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

  • Are you hosting this on github? Can you share a link to your project page? – raphael Nov 25 '15 at 1:54
1

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">.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.