Как сделать так, чтобы мой маршрут был виден на карте листовки?
У меня есть функциональность на сайте, которая получает координаты пользователя и создает маршрут к месту, куда пользователь направляется. как например http://www.liedman.net/leaflet-routing-machine/tutorials/basic-usage/. Однако, это не работает, я не могу понять, что с кодом
// get place coordinates from a django variable I passed in the template
const latitude = document.getElementById('lat').textContent;
const longtitude = document.getElementById('lon').textContent;
let btn = document.getElementById('create_route');
console.log('check w')
// Creating map options
let mapOptions = {
center: [latitude, longtitude],
zoom: 18,
zoomControl: true,
zoomAnimation: true,
}
// Creating a map object (I'm guessing the error is somewhere down here...)
var map = new L.map('map', mapOptions);
var layer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
});
map.addLayer(layer);
L.marker([latitude,longtitude]).addTo(map);
btn.addEventListener("click",function create_route(e){
function success(pos) {
const crd = pos.coords;
let crdLat = crd.latitude, crdLon = crd.longitude;
L.Routing.control({
waypoints: [
L.latLng(latitude,longtitude),
L.latLng(crdLat,crdLon)
],
autoRoute: true,
routeWhileDragging: true
}).addTo(map);
}
//get user location
navigator.geolocation.getCurrentPosition(success);
})
При нажатии на кнопку на карте появляются два маркера, но нужный мне путь/маршрут не отображается. Также я получаю эту ошибку в консоли.
leaflet-routing-machine.js:88
GET https://router.project-osrm.org/route/v1/driving/-77.3396498,25.0781526;55.4333172,-4.6083844?overview=false&alternatives=true&steps=true&hints=; 400
и это leaflet-routing-machine.js:15868 Ошибка маршрутизации: { "сообщение": "HTTP-запрос не удался: неопределено", "url": "https://router.project-osrm.org/route/v1/driving/-77.3396498,25.0781526;55.4333172,-4.6083844?overview=false&alternatives=true&steps=true&hints=;", "status": -1, "target": {} }
Любая помощь будет оценена по достоинству. Заранее спасибо.