Well, here is my code, taken and modified from the demo. I found out how to set points from code (start, destination). The function executes as expected but the request result is stil “Unknown error”.
function setupRoutingAPI(map, ghRouting) {
map.setView([52.521235, 13.3992], 12);
var iconObject = L.icon({
iconUrl: './resources/images/marker.png',
shadowSize: [50, 64],
shadowAnchor: [4, 62],
iconAnchor: [12, 40]
});
var routingLayer = L.geoJson().addTo(map);
routingLayer.options = {
style: {color: "#00cc33", "weight": 5, "opacity": 0.6}
};
ghRouting.clearPoints();
routingLayer.clearLayers();
var start = L.latLng(50.123456, 9.123456);
var destination = L.latLng(50.654321, 9.654321);
L.marker(start, {icon: iconObject}).addTo(routingLayer);
ghRouting.addPoint(new GHInput(start.lat, start.lng));
L.marker(destination, {icon: iconObject}).addTo(routingLayer);
ghRouting.addPoint(new GHInput(destination.lat, destination.lng));
// Calculate route!
ghRouting.doRequest(function (json) {
if (json.message) {
var str = "An error occured: " + json.message;
if (json.hints)
str += json.hints;
window.alert(str);
} else {
var path = json.paths[0];
routingLayer.addData({
"type": "Feature",
"geometry": path.points
});
if (path.bbox) {
var minLon = path.bbox[0];
var minLat = path.bbox[1];
var maxLon = path.bbox[2];
var maxLat = path.bbox[3];
var tmpB = new L.LatLngBounds(new L.LatLng(minLat, minLon), new L.LatLng(maxLat, maxLon));
map.fitBounds(tmpB);
}
}
});
}