首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Mapzen以字符串或JSON的形式返回逐行数据

使用Mapzen以字符串或JSON的形式返回逐行数据
EN

Stack Overflow用户
提问于 2017-01-30 22:54:41
回答 1查看 119关注 0票数 1

我一直在使用这个库从一个集合的路线上用Mapzen的逐转数据API获取机动数据。虽然设置地图和路线没有问题,但我很难访问包含车辆需要在每个点(左、右等)转弯的对象/字符串,以便能够与GPS一起使用它。将其作为字符串或JSON获得将是完美的,我只是不知道在这一点上该做什么。

我发现在文档中有一种方法可以做到这一点,但我要么不理解,要么试图用错误的方式来做,所以我想知道是否有更有经验的人可以帮助我,或者给我一些关于我如何才能做到这一点的想法。

到目前为止,我的脚本代码如下(所有文件都附在下面):

代码语言:javascript
复制
// Create a map. Targets div with id 'map'.
var map = L.map('map');

var layer = Tangram.leafletLayer({
  scene: 'https://raw.githubusercontent.com/tangrams/refill-style/gh-pages/refill-style.yaml',
  attribution: '<a href="https://mapzen.com/tangram" target="_blank">Tangram</a> | <a href="http://www.openstreetmap.org/about" target="_blank">&copy; OSM contributors | <a href="https://mapzen.com/" target="_blank">Mapzen</a>',
}); // End of layer.

// Adds the styles and attributions to the map.
layer.addTo(map);

// Set the default view of the map (Bristol).
// No need to use this when a route is being displayed.
//map.setView([51.4545,-2.5879], 16);

// Sets a route and adds it to the map, it requires two points and their respective latitude and longitude.
L.Routing.control({
      waypoints: [
        L.latLng(51.4998,-2.5468),
        L.latLng(51.5055,-2.5603)
      ]
    }).addTo(map);

// I used a log to try and find out which object has the turn-by-turn data. No luck so far.
console.log(L.Routing.mapzen('mapzen-xxxxxxx', `{costing:'auto'}));

到目前为止我所拥有的项目文件(在GitHub文章的末尾):https://github.com/mapzen/lrm-mapzen/issues/72

谢谢你的阅读,如果有人帮我这个忙,我会非常感激的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-12 01:49:07

以上提到的github问题给出了这个答案:

代码语言:javascript
复制
var sampleLatLngs = [L.Routing.waypoint(L.latLng(51.4998,-2.5468)), L.Routing.waypoint(L.latLng(51.5055,-2.5603))];

// You can grab free api key at https://mapzen.com/developers
var router = L.Routing.mapzen('your-api-key', {costing: 'pedestrian'});

// We are just going to print out route turned from the server
var sampleFunction = function(err, routes) {
    // Check your browser console
    console.log(routes);
}

router.route(sampleLatLngs, sampleFunction);

如果您检查浏览器,您将看到来自服务器的响应。instructions属性可能有您想要的信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41946875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档