javascript - Mapbox 方向:出现错误 {"message":"Latitude must be between -90 and 90","code":"InvalidInput"}
问题描述
我正在构建一个网站应用程序,允许用户在地图上设置多个航点并计算完整路线并逐步给出方向。基本上,我正在遍历具有经度和纬度值的标记列表。我尝试替换示例经度和纬度值(-84.518641,39.134270;-84.512023,39.102779)并且它有效,但我的标记设置在澳大利亚,因此纬度超过 90。我尝试交换经度和纬度值但没有奏效任何一个。
当前出现错误:{“消息”:“纬度必须在 -90 和 90 之间”,“代码”:“无效输入”}
任何帮助将非常感激。
干杯!
下面的代码:
`const getRoute = (end) => {
var start = [markers[0].lat,markers[0].lng];
// var end = [markers[1].lat,markers[1].lng];
console.log(start);
console.log(end);
var url = `https://api.mapbox.com/directions/v5/mapbox/walking/${start[0]},${start[1]};${end[0]},${end[1]}?steps=true&geometries=geojson&access_token=${mapboxgl.accessToken}`;
// console.log(start);
// // console.log(end);
console.log(url);
var req = new XMLHttpRequest();
req.open('GET', url, true);
req.onload = function() {
var json = JSON.parse(req.response);
var data = json.routes[0];
var route = data.geometry.coordinates;
var geojson = {
type: 'Feature',
properties: {},
geometry: {
type: 'LineString',
coordinates: route
}
};
// if the route already exists on the map, reset it using setData
if (map.getSource('route')) {
map.getSource('route').setData(geojson);
} else { // otherwise, make a new request
map.addLayer({
id: 'route',
type: 'line',
source: {
type: 'geojson',
data: {
type: 'Feature',
properties: {},
geometry: {
type: 'LineString',
coordinates: geojson
}
}
},
layout: {
'line-join': 'round',
'line-cap': 'round'
},
paint: {
'line-color': '#3887be',
'line-width': 5,
'line-opacity': 0.75
}
});
}
// add turn instructions here at the end
};
req.send();
// End of getInitRoute
};
getRoute([markers[1].lat,markers[1].lng]);
map.on('load', function() {
// make an initial directions request that
// starts and ends at the same location
getRoute(start);
// Add starting point to the map
map.addLayer({
id: 'point',
type: 'circle',
source: {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [{
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: start
}
}
]
}
},
paint: {
'circle-radius': 10,
'circle-color': '#3887be'
}
});
// this is where the code from the next step will go
});
// End of If statement
}
// end of InitMapbox
};`
解决方案
推荐阅读
- r - 用 1 代替刻度线√
- python - 如何获取用户的角色 discord.py
- python - 如何使用 MySQL-Connector 从 Python 中的 MySQL 存储过程中检索 out 参数?
- dc.js - 连接两个 json 对象时无法显示绘图
- c++ - 如何在 C++ 模板中调用类的构造函数?
- mac-catalyst - 调整窗口大小时未调用 didUpdate
- html - 在 Swift 中从 HTML 字符串中提取多个元素
- facebook-opengraph - Facebook 爬虫 cURL:AWS CLoudFront 上的 28 (OPERATION_TIMEOUTED)
- c++ - 如何在 C++ 中使用 UTF-8 和 Unicode?C++20 char8_t 有多大?
- validation - 是否有根据不同单元格的内容锁定已经具有数据验证的单元格的功能?