ymaps3.route({
points: [
[37.6156, 55.7522],
[37.60266102371218, 55.75392292398344]
],
type: 'driving'
}).then((route) => {
console.log(route);
});ymaps3.ready.then(() => {
ymaps3.getDefaultConfig().setApikeys({router: ''});
});
Сергей, ошибка возникла из-за неточности в коде. Вы можете выполнить построение маршрута по этому примеру.
Построение маршрута доступно на бесплатном тарифе, только требуется API-ключ, так как вы используете версию JavaScript 3.0.
ymaps3.ready.then(() => {
ymaps3.getDefaultConfig().setApikeys({router: ''});
});await ymaps3.ready;
const {YMap,YMapDefaultSchemeLayer,YMapDefaultFeaturesLayer,YMapControls,YMapMarker,YMapListener,YMapFeature} = ymaps3;
const {YMapZoomControl,YMapGeolocationControl} = await ymaps3.import('@yandex/ymaps3-controls@0.0.1');
const {YMapDefaultMarker} = await ymaps3.import('@yandex/ymaps3-markers@0.0.1');
const MAP = new YMap(document.getElementById('map'),{
location: {
center: center,
zoom: zoom
}
});
let ROUTE_LINE = new YMapFeature({
geometry:{
type: 'LineString',
coordinates: []
}, style: {
stroke: [{
color: opMapROUTING.line.color,
width: 6,
opacity: 0.8
}]
}
});
MAP.addChild(ROUTE_LINE);
fetch(atumquiz.arrayToUrlParams('https://api.routing.yandex.net/v2/route',{
apikey: opMapROUTING.apikey,
waypoints:`${latLon}|${latLon}`,
mode: 'truck'
}), {
headers: {
'Accept': 'application/json'
}
}).then(response => {
return response.json();
}).then(routes => {
if(routes.errors){
ROUTE_LINE.update({geometry:{type: "LineString", coordinates: []}});
console.error(routes.errors[0]);
}else{
if(routes.route.legs[0].status = "OK"){
let LINE_latlngs = [];
routes.route.legs.forEach(leg => {
leg.steps.forEach(step => {
step.polyline.points.forEach(point => {
LINE_latlngs.push([point[1],point[0]]);
});
});
});
ROUTE_LINE.update({geometry:{type: "LineString", coordinates: LINE_latlngs}});
}else{
ROUTE_LINE.update({geometry:{type: "LineString", coordinates: []}});
console.error(`Route not found`);
}
}
});