Mapbox routing using the mapbox API

I'm not very good at coding and am currently using the mapbox API to create a dotted map. But I can’t find anything in the basic routing between the position of the user using "geolocation" and the points on my map. Is there any way to do this in the API? I would like the user to be able to find the path to the places that I have on the map, and between them. Your help will be greatly appreciated.

Yours faithfully

Al

+5
source share
2 answers

There is no routing in Mapbox api that is ready for production. They are working on a preview, see here: https://www.mapbox.com/developers/api/directions/

mapbox, . . : fooobar.com/questions/159213/...

+3

Mapbox.directions . context map, ( clickable: false, ). MouseEvent, latlng, . , . :

$('#lblStatus').html("Calculating route....");

// **** units is not working yet in the current Mapbox release
moDirections = L.mapbox.directions({
    profile: 'mapbox.driving',
    units: 'metric'
});

moDirections.on('load', function (directions) {
    // Loop through all route coordinates and determine bounds for route.
    var minLat = 90, minLng = 180, maxLat = -90, maxLng = -180;
    var lat, lng;
    directions.routes[0].geometry.coordinates.forEach(function (laCoordinate, index) {
        lat = laCoordinate[1];
        lng = laCoordinate[0];
        if (lat < minLat) {
            minLat = lat;
        }
        if (lng < minLng) {
            minLng = lng;
        }
        if (lat > maxLat) {
            maxLat = lat;
        }
        if (lng > maxLng) {
            maxLng = lng;
        }
    });
    var loBounds = L.latLngBounds(L.latLng(minLat, minLng), L.latLng(maxLat, maxLng));
    moMap.fitBounds(loBounds);

    $('#lblStatus').html("");
});

moDirections.setOrigin(loStart);
moDirections.setDestination(loEnd);
moDirections.query();

moDirectionsLayer = L.mapbox.directions.layer(moDirections).addTo(moMap);
moDirectionsErrorsControl = L.mapbox.directions.errorsControl('pnlRouteErrors', moDirections);
moDirectionsRoutesControl = L.mapbox.directions.routesControl('pnlAlternateRoutes', moDirections);
moDirectionsInstructionsControl = L.mapbox.directions.instructionsControl('pnlRouteInstructions', moDirections);

pnl * - divs, .

. : https://github.com/mapbox/mapbox-directions.js

: https://www.mapbox.com/mapbox.js/example/v1.0.0/mapbox-directions/, , Input .

+3

Source: https://habr.com/ru/post/1531444/


All Articles