TL;博士
如果您在第二个 API 请求坐标中包含更多数字,与第一个请求中的数字一样多,这应该可以解决您的问题。
完整的 URL (带有排除的 API 密钥)是:
https://transit.router.hereapi.com/v8/routes?apiKey={key}&origin=22.5058,88.3640&destination=22.6420,88.4312
我在下面的详细答案下面有一个现场演示,您可以在其中粘贴您的 API 密钥并运行查询以查看此操作。
详细解答
在您的第二个示例中,您的纬度和经度坐标需要更具体,因为它们与您正在寻找往返路线的实际位置不匹配。
而不是使用
origin=22.50,88.36&destination=22.64,88.43
使用✅</p>
origin=22.5058,88.3640&destination=22.6420,88.4312
我从 Google 中提取了这两个位置的坐标……</p>
搜索“焦特布尔公园坐标”:

搜索“Dum Dum 坐标”:

完整的 URL (带有排除的 API 密钥)是:
https://transit.router.hereapi.com/v8/routes?apiKey={key}&origin=22.5058,88.3640&destination=22.6420,88.4312
生成的 JSON 数据会生成三种不同的运输路线。
现场演示
这是一个实际演示,您可以在其中安全地使用自己的 API 密钥,并根据需要调整起点和目的地 lat/lng 坐标以从 API 生成数据:
const getById = id => document.getElementById(id),
apiKey = getById('api-key'),
origLat = getById('orig-lat'),
origLng = getById('orig-lng'),
destLat = getById('dest-lat'),
destLng = getById('dest-lng'),
button = getById('submit'),
output = getById('output');
const getDirections = () => {
fetch(`https://transit.router.hereapi.com/v8/routes?apiKey=${apiKey}&origin=${origLat},${origLng}&destination=${destLat},${destLng}`).then(res => res.json()).then(data => output.innerHTML = JSON.stringify(data, null, 2)).catch(error => output.innerHTML = error);
};
[apiKey, origLat, origLng, destLat, destLng].forEach(field => field.toString = () => field.value);
button.addEventListener('click', getDirections);
html {
height: 100%;
box-sizing: border-box;
font-family: consolas, monospace;
}
*, *::before, *::after {
box-sizing: inherit;
font: inherit;
}
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: stretch;
gap: 20px;
min-height: 100%;
margin: 0;
font-smooth: antialiased;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
overflow: hidden scroll;
-ms-overflow-style: none;
scrollbar-width: none;
}
body::-webkit-scrollbar {
width: 0;
display: none;
}
h2 {
width: 100%;
margin: 0;
padding: 10px 20px;
background-color: #000;
font-size: 120%;
font-weight: 700;
color: #fff;
text-align: center;
}
#fields {
display: flex;
flex-direction: column;
gap: 5px;
}
label {
display: flex;
align-items: center;
justify-content: flex-end;
width: 100%;
max-width: 300px;
}
input {
appearance: none;
-webkit-appearance: none;
width: 100px;
margin-left: 5px;
padding: 5px 10px;
background-color: #ddd;
border: none;
text-align: right;
}
pre {
width: 100%;
padding: 10px;
border-top: 1px solid #000;
flex: 1;
margin: 0;
overflow-y: hidden;
background-color: #ddd;
font-size: 85%;
}
<h2>Here API demo</h2>
<div id="fields">
<label>API Key<input id="api-key" placeholder="API key"></label>
<label>Origin Latitude<input id="orig-lat" value="22.5058"></label>
<label>Origin Longitude<input id="orig-lng" value="88.3640"></label>
<label>Destination Latitude<input id="dest-lat" value="22.6420"></label>
<label>Destination Longitude<input id="dest-lng" value="88.4312"></label>
</div>
<button id="submit">Run a query</button>
<pre id="output">Run a query using the button above to load the results here.</pre>