Mapbox驾驶方向
Mapbox Driving Direction
我想使用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。谢谢
相关文章:
- ng映射方向备选方案
- RubyonRails——构建交互式接口应该朝哪个方向发展
- 需要帮助谷歌地图方向面板在FancyBox中显示
- 在D3.js中,有没有任何方法可以将x和y方向上的滚动事件绑定到平移svg
- 我怎样才能知道用户滑动的方向
- 使用谷歌地图API和phonegap显示当前位置+方向
- 用真或假初始化变量是否在 Javascript 中建立了内容的方向
- 带有自定义标记的谷歌地图方向APIv3
- 在角度方向的元素之前插入
- 更改D3方向力图中箭头标记的方向
- fullpage.js在滚动时更改滚动方向
- 如何在谷歌地图api v3中获得无公里驾驶距离
- 基于谷歌地图API方向服务构建的替代路线
- 如何将字符串地址传递到传单路由机,以根据字符串地址获得方向
- 谷歌地图API,驾驶方向渲染
- Mapbox驾驶方向
- 用于在Google Maps API V3中显示和隐藏驾驶方向上的所有标记的复选框
- 圆半径与驾驶方向在必应地图
- Google Maps API v3:首先加载2个位置的地图上的驾驶方向
- 谷歌地图v3驾驶方向与一个可点击的路线/信息窗口