graphhopper / directions-api

Issues for the GraphHopper Directions API
https://graphhopper.com/api/1/docs/
60 stars 25 forks source link

What is the correct way to enter from_points and to_points? #86

Closed jgallardou closed 4 years ago

jgallardou commented 5 years ago

at the time of making the request it returns an error:

{
    "message": "Bad Request",
    "hints": [
        {
            "details": "java.lang.IllegalArgumentException",
            "message": "Cannot find from_points: 0"
        },
        {
            "details": "java.lang.IllegalArgumentException",
            "message": "Cannot find to_points: 0"
        }
    ],
    "status": "finished"
}

var url = "https://graphhopper.com/api/1/matrix?key=myKey";
        var data ={
    "from_points": [
        [
            -33.4673461,
            -70.6247406
        ]
    ],
    "to_points": [
        [
            -33.794796,
            -70.913138
        ]
    ],
    "from_point_hints": [
        "ñuñoa"
    ],
    "to_point_hints": [
        "places 1"
    ],
    "out_arrays": [
        "times",
        "distances"
    ],
    "vehicle": "car"
};

        $.ajax({
            beforeSend: function(xhrObj) {
                xhrObj.setRequestHeader("Content-Type", "application/json");
                xhrObj.setRequestHeader("Accept", "application/json");
            },
            url: url,
            data: JSON.stringify(data),
            type: 'POST', //en este caso
            dataType: 'json',
            success: function(response) {
                console.log(response);
            },
            error: function(error) {
                console.log(error);
            }
        });
karussell commented 5 years ago

Can you try to switch the latitude with the longitude?

-33.4673461, -70.6247406 -> -70.6247406,-33.4673461

Unfortunately for the GET request it is point=lat,lon and for POST request it is an array [lon,lat].