graphhopper / directions-api-js-client

JavaScript client for the GraphHopper Directions API
https://graphhopper.com/api/1/examples
108 stars 85 forks source link

An error occured: Bad Request #39

Closed jomarocas closed 6 years ago

jomarocas commented 6 years ago

An error occured: Bad Request - for url https://graphhopper.com/api/1/vrp/optimize?key=xxxxx

Hi

i create a local instance for testing localhost/graphhopper i use the examples document for create my testing code i only modify the following code in examples, i put my key and try the demo localhost, working good with all items except when i change the coords lat and lon in the file tsp_lonlan_new.json modify demo.js for set the center map

    $("#set_example_tsp").click(function () {
        $.getJSON("route-optimization-examples/tsp_lonlat_new.json?v=" + exampleVersion, function (jsonData) {

            clearMap();
            map.setView([4, -74], 6);
            $("#vrp-response").text("Calculating ...");
            ghOptimization.doRequest(jsonData)
                .then(optimizeResponse)
                .catch(optimizeError);
        });
    });

modify route-optimization-examples/tsp_lonlat_new.json for points

{
  "vehicles" : [{
    "vehicle_id" : "vehicle1",
    "start_address" : {
        "location_id" : "v1_startLoc",
        "lon": 4.713042,
        "lat": -74.05115
    },
    "type_id" : "vehicle_type_1"
  }],
  "vehicle_types" : [{
    "type_id" : "vehicle_type_1",
    "profile" : "car"
  }],
  "services" : [
    {
      "id": "b1",
      "name": "drink_bionade_in_rostock",
      "address": {
        "location_id": "loc_b1",
        "lon": 4.663407,
        "lat": -74.049069
      }
    },
    {
      "id": "b2",
      "name": "drink_cola_in_berlin",
      "address": {
        "location_id": "loc_b2",
        "lon": 4.744023,
        "lat": -74.064401
      }
    }
  ]
}

thanks for any help

karussell commented 6 years ago

try switching lat & lon:

{
  "vehicles" : [{
    "vehicle_id" : "vehicle1",
    "start_address" : {
        "location_id" : "v1_startLoc",
        "lon": -74.05115,
        "lat": 4.713042
    },
    "type_id" : "vehicle_type_1"
  }],
  "vehicle_types" : [{
    "type_id" : "vehicle_type_1",
    "profile" : "car"
  }],
  "services" : [
    {
      "id": "b1",
      "name": "drink_bionade_in_rostock",
      "address": {
        "location_id": "loc_b1",
        "lon": -74.049069,
        "lat": 4.663407
      }
    },
    {
      "id": "b2",
      "name": "drink_cola_in_berlin",
      "address": {
        "location_id": "loc_b2",
        "lon": -74.064401,
        "lat": 4.744023
      }
    }
  ]
}
jomarocas commented 6 years ago

oh sorry, yes was this