首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenRouteService方向应用编程接口用法

OpenRouteService方向应用编程接口用法
EN

Stack Overflow用户
提问于 2019-02-28 21:01:24
回答 1查看 422关注 0票数 2

因此,我正在尝试使用开放路由服务方向API https://openrouteservice.org/dev/#/api-docs/directions/get,但到目前为止,我找不到任何关于如何使用它的教程。

对于初学者的问题,我很抱歉..这是我尝试使用的代码:

代码语言:javascript
复制
var request = new XMLHttpRequest();

request.open('GET', 'https://api.openrouteservice.org/directions?api_key=<API-KEY>&coordinates=24.942729,37.443186%7C24.943709,37.444405&profile=cycling-regular');

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();

问题是开始和结束坐标的值都在链接中,我如何在其中放入一个变量,以便每次用户登录一个新的坐标值时,它都会在链接中更新?

EN

回答 1

Stack Overflow用户

发布于 2021-11-29 21:30:26

您可以简单地使用POST方法,而不是Get,并在主体中以JSON数据的形式发送数据。如下所示:

代码语言:javascript
复制
let request = new XMLHttpRequest();

request.open('POST', "https://api.openrouteservice.org/v2/directions/cycling-regular/geojson");

request.setRequestHeader('Accept', 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Authorization', '5b3ce3597851110001cf62488303e1e1bcb64deb91105af7032e30d4');

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

const body = '{"coordinates":[[-73.47882,45.56434],[-73.4853,45.5578]],"maneuvers":"false","options":{"avoid_features":["steps"]}}';

request.send(body);

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

https://stackoverflow.com/questions/54926373

复制
相关文章

相似问题

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