I installed api with npm install graphhopper-js-api-client --save
Added require('graphhopper-js-api-client'); to my code.
Added this code below and used it.
var defaultKey = "[Sign-up for free and get your own key: https://www.graphhopper.com/products/]";
var profile = "car";
var host;
var ghRouting = new GraphHopper.Routing({key: defaultKey, host: host, vehicle: profile, elevation: false});
// If you only need e.g. Routing, you can only require the needed parts
//var ghRouting = new GraphHopperRouting({key: defaultKey, host: host, vehicle: profile, elevation: false});
// Setup your own Points
ghRouting.addPoint(new GHInput(47.400905, 8.534317));
ghRouting.addPoint(new GHInput(47.394108, 8.538265));
ghRouting.doRequest()
.then(function(json){
// Add your own result handling here
console.log(json);
})
.catch(function(err){
console.error(err.message);
});
Is there something wrong? It is first time to use API for me. Please help me.
The GraphHopper Js client lets you directly work on the point objects, it decodes the encoded polyline already under the hood (you don’t need to do that!).