2015-12-08 49 views
0

我想使用mapbox来使用其驾驶方向API的mapView。我想使用这个API给我已经定义的两个位置之间的路线。假设我们知道这些地点,我们不应该在它们之间划出路线。此外,用户应该能够将位置(地图上的市场/销钉)更改为他们想要的任何位置,以便mapbox相应地绘制适当的路线。Mapbox行车方向

这是可以用mapbox Driving Direction做的事情,但我也想要的是能够获取位置,例如,当用户在输入框中键入或使用市场来定位原点和目的地时后端我希望能够跟踪这些位置并记录它们。

的Javascript Mapbox PHP

<div id='map'></div> 
<div id='inputs'></div> 
<div id='errors'></div> 
<!-- 
<div id='directions'> 
    <div id='routes'></div> 
    <div id='instructions'></div> 
</div> 
--> 
<script> 
L.mapbox.accessToken = 'pk.eyJ1IjoiZmFyc2hpZGFsYXZpIiwiYSI6ImNpZjNmNTRrYzQ0b2xzNWx1bXN5MnlmdjUifQ.IvZZfdiPe4rxQNolE88fhg'; 

var start = {lat: '<?php echo $__logbook->__route[0]->latitude ?>', lng: '<?php echo $__logbook->__route[0]->longitude ?>'}; 
var finish = {lat: '<?php echo end($__logbook->__route)->latitude ?>', lng: '<?php echo end($__logbook->__route)->longitude ?>'}; 

var map = L.mapbox.map('map', 'mapbox.streets', {zoomControl: false}).setView([start.lat, start.lng], 6); 

map.attributionControl.setPosition('bottomleft'); 

var directions = L.mapbox.directions(); 

directions.setOrigin(L.latLng(start.lat, start.lng)); 
directions.setDestination(L.latLng(finish.lat, finish.lng)); 
directions.query(); 

var directionsLayer = L.mapbox.directions.layer(directions).addTo(map); 
var directionsInputControl = L.mapbox.directions.inputControl('inputs', 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); 

console.log(L.mapbox.directions.inputControl); 

$('#btn').click(function() { 
    var obj = $('#live'); 
    obj.html('I just changed!!!'); 
    obj.trigger('contentchanged'); 
}); 

$('#inputs').bind('contentchanged', function(e) { 
    console.log(L.mapbox.directions.inputControl); 
}); 

</script> 
+0

我想出了解决方案,我将directions.js加载到我的本地库中,并做了很多更改,实际上我将它与角度和范围(展开)合并在一起,并且它像魅力一样工作。我很高兴揭露我的一些代码,让我成为一名PM。谢谢 – Farshid

回答

0

我找出解决办法,我装了directions.js到我的本地库,并提出了很多的变化,事实上我与我的角度和范围(其合并部署),它的功能就像一个魅力。我很高兴揭露我的一些代码,让我成为一名PM。谢谢