- // documentation
- // https://github.com/graphhopper/graphhopper/blob/master/docs/web/api-doc.md
- var url = document.location.protocol + "//graphhopper.com/api/1/route?" +
- vehicleParam +
- "&locale=" + I18n.currentLocale() +
- "&key=LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn" +
- "&type=jsonp" +
- "&instructions=true";
-
- for (var i = 0; i < points.length; i++) {
- url += "&point=" + points[i].lat + ',' + points[i].lng;
- }
-
- $.ajax({
- url: url,
- dataType: 'jsonp',
+ // GraphHopper Directions API documentation
+ // https://graphhopper.com/api/1/docs/routing/
+ return $.ajax({
+ url: OSM.GRAPHHOPPER_URL,
+ data: {
+ vehicle: vehicleType,
+ locale: I18n.currentLocale(),
+ key: "LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn",
+ elevation: false,
+ instructions: true,
+ turn_costs: vehicleType === "car",
+ point: points.map(function (p) { return p.lat + "," + p.lng; })
+ },
+ traditional: true,
+ dataType: "json",