Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Direction plotted isnt updating when the origin's lat and lan gets changed #1278

Open
Deliforce opened this issue Jan 29, 2019 · 0 comments
Open

Comments

@Deliforce
Copy link

Deliforce commented Jan 29, 2019

Hi,
i am facing the problem in updating the direction path which is plotted by the call of direction api using setOrigin and SetDestination in mapbox.js, now the problem is that how can i update the direction path when the origin's lat and lan getting changed at a interval of 15 sec.

The below is the javascript code to implement the direction api,so know when the orgin lat and lng changes ,how can i updated the direction path in the below code.

L.mapbox.accessToken = 'pk.eyJ1IjoiY2hhbmRydWRlbGlmb3JjZSIsImEiOiJjamMyMXkxdHYwYTlkMzNtd3MydWcwYXhlIn0.QVVhxj5S-dnI89ZXjaUJtA';

var map = L.mapbox.map('map', 'mapbox.streets', {
center: [12.971599,77.594566],
zoom: 13
});

 var directions = L.mapbox.directions({
            //  profile: 'mapbox.walking'
        
        });


        var destination = {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [77.726822,12.989100]
            },
            "properties": {
                "title": 'me'
            }
        };

        var origin = {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [77.631791,13.023008]
            },
            "properties": {
                "title": 'You'
            }
        };

        console.log('origin', origin);
        console.log('destination', destination);

        directions.setOrigin(origin).setDestination(destination)
        directions.query({}, function (err, result) {

        })

        var directionsLayer = L.mapbox.directions.layer(directions)
            .addTo(map);

        var directionsErrorsControl = L.mapbox.directions.errorsControl('errors', directions)
            .addTo(map);

        var directionsRoutesControl = L.mapbox.directions.routesControl('routes', directions)
            .addTo(map);

        var directionsInstructionsControl = L.mapbox.directions.instructionsControl('instructions', directions)
            .addTo(map);

var originFit = L.latLng(13.023008,77.726822),
destinationFit = L.latLng(12.989100,77.726822),
bounds = L.latLngBounds(destinationFit,originFit);
map.fitBounds(bounds);

The below is the html code,

<script src='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js'></script> <script src='https://api.mapbox.com/mapbox.js/plugins/mapbox-directions.js/v0.4.0/mapbox.directions.js'></script>

Kindly provide me the solution ASAP ,thank u in advance.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant