Mapbox驾驶方向

Mapbox Driving Direction

本文关键字:方向 驾驶 Mapbox      更新时间:2023-09-26

我想使用mapbox的驱动方向API为mapView使用mapbox。我想使用这个api来提供已经定义的两个位置之间的路由。假设我们知道这些地点,不,我们应该在它们之间划出路线。此外,用户应该能够将位置(地图上的市场/引脚)更改为他们想要的任何位置,因此地图框应该相应地绘制适当的路线。

这是可以使用mapbox Driving Direction进行的操作,但我也希望能够获得位置,例如,当用户在输入框中输入或使用市场定位起点和终点时,我希望能够在后端跟踪这些位置并将其记录下来。

JavascriptMapboxPHP

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

我找到了解决方案,我把directions.js加载到我的本地库中,并做了很多更改,事实上,我把它与我的angular和scope(deploy)合并在一起,它就像一个魅力。我很高兴公开我的一些代码,给我留下一个PM。谢谢