我正在使用MapBox绘制通过在rails上构建的用户生成表单提交的兴趣点。目前用户输入一个地址,然后地址通过gem(地理编码器)计算它的Lat和Lng。从我通过gon gem将数据从rails传递给javascript,在所有感兴趣的点上运行forEach循环,然后使用lat和lng在地图上绘图。
现在我想获得感兴趣点之间的行车路线,a到b到c等等.MapBox有一个路线部分,但路线基于地图上的点击事件,而不是存储输入。一直在与这个摔跤,谷歌并没有取得丰硕成果。
非常感谢有关如何使用MapBox获取绘制点之间方向的链接和建议。
干杯。
答案 0 :(得分:1)
使用Mapbox Directions API时,您可以提供自己的航点,以分号分隔的坐标列表。
http://api.tiles.mapbox.com/v4/directions/{profile}/{waypoints}.json?access_token=<your access token>
航点应该最少包含两个坐标,即起点和终点坐标。这个API应该完全符合您的要求。有关Mapbox方向API的更多信息,请访问here
答案 1 :(得分:0)
我不知道mapBox。但请注意:浏览器会告诉您您的位置;它不是Google Mpas,mapBox或......
<script type="text/javascript">
function initialize(position, accuracy) {
alert(
'Lat: ' + position.lat + ' - Lng' + position.lng + ' - accuracy: ' + accuracy + 'm'
);
//// example for Google Maps
// var latlng = new google.maps.LatLng(position.lat, position.lng);
// ...
}
// request is succesful
function locationFound(position) {
initialize(
{lat: position.coords.latitude, lng: position.coords.longitude},
position.coords.accuracy
);
}
function locationNotFound() {
alert('Not able to find your location');
}
function page_loaded() {
// the page is loaded, we can send a request to search for the location of the user
navigator.geolocation.getCurrentPosition(locationFound, locationNotFound);
}
</script>
<body onload="page_loaded()">
<div id="map-canvas"></div>
</body>