I am new in ORS. Cannot run javascript direction example, after implementing my api key on the right location, running “direction” example, error message comes back: " Please provide an API key via ?api_key=mykey query parameter"?
.
.
window.onload = function() {
var apiKey = location.search.split(‘api_key=’)[1];
if (!apiKey || apiKey === "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") {
var node = document.getElementById("driving-car-directions");
node.innerHTML = "<p>Please provide an API key via <b>?api_key=mykey</b> query parameter </p>";
Hi @gerritmueller,
the only thing that is not working in the directions example is the ‘geometry_format’ parameter.
I’m not sure what you did with the location but if you add your API key in
let orsDirections = new Openrouteservice.Directions({
api_key: "xxx"
});
like this example says, there shouldn’t be any problems
If you copy the following into an html file and adjust the location of the openrouteservice-js script and your api key it should work
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="dist/ors-js-client.js"></script>
<script>
window.onload = function() {
let orsDirections = new Openrouteservice.Directions({
api_key: "xxx"
});
orsDirections.calculate({
coordinates: [[8.690958, 49.404662], [8.687868, 49.390139]],
profile: "driving-car",
extra_info: ["waytype", "steepness"],
format: "json"
})
.then(function(json) {
// Add your own result handling here
console.log(JSON.stringify(json));
})
.catch(function(err) {
console.error(err);
});
};
</script>
</head>
<body>
Check the developer console
</body>
</html>
Thank you for your quick and good response!