<div dir="ltr"><div><div>Hey Patrick,<br>Thanks for the help.<br><br></div>Sorry but I'm a little bit new with Javascript environment. I see that the first link you sent me is contained in a full-working project. In order to use the functionalities of the .js file, do I have to include the whole project in some way, or can I re-use the single file on my side without any extra-dependencies? Also, is the leaflet routing machine is useful to run many tests on the OSRM server with random locations values each time?<br><br></div><div>Romain.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-02-12 11:34 GMT+01:00 Patrick Niklaus <span dir="ltr"><<a href="mailto:patrick.niklaus@student.kit.edu" target="_blank">patrick.niklaus@student.kit.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey Romain,<br><br>Leaflet-Routing-Machine is a good reference for seeing how to query the OSRM route with javascript from a browser:<br><br><a href="https://github.com/perliedman/leaflet-routing-machine/blob/master/src/L.Routing.OSRM.js" target="_blank">https://github.com/perliedman/leaflet-routing-machine/blob/master/src/L.Routing.OSRM.js</a><br><br>They use corslite [1] to do the json querry.<br><br>[1] <a href="https://github.com/perliedman/leaflet-routing-machine/blob/master/src/L.Routing.OSRM.js#L55" target="_blank">https://github.com/perliedman/leaflet-routing-machine/blob/master/src/L.Routing.OSRM.js#L55</a><br><br>Good luck,<br>Patrick<br><br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Thu, Feb 12, 2015 at 10:46 AM, Romain NKONGO <span dir="ltr"><<a href="mailto:romain.rnk49@gmail.com" target="_blank">romain.rnk49@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div><div><div><div><div><div>Hello to all the OSRM community.<br><br></div>I'm a french student who works on a university project, along with my supervisor and uses the open source project OSRM to achieve it.<br><br></div>At some point, I have to run some tests (like thousands of tests) to extract some values from the JSON outputs (e.g. the total time). Now our problem is we tried several ways to do this, by sending HTTP GET requests to the running server and treat the returned response as JSON. But we tried with Javascript, jQuery and AngularJS, with functions like $resource.get, jQuery.getJSON $http.get or $http.jsonp and we never managed to get the returned response in a way that we could use it for further treatment in our script. Actually, we were able to send the requests to the server but the response is returned in the fom of an URL link which contains the JSON output in its body, not in the form of a variable in our Javascript that we could manipulate.<br><br></div>As a matter of fact, we have two issues for this :<br></div>- some of the functions we used  (which are based on jsonp) added a callback parameter to the sent URL, so the request became invalid with 'Query malformed at the position' errors<br></div>- I've seen in the OSRM documentation that the JSON output is encoded with the Google polyline algorithm so it could be an invalid JSON for Javascript (we also observed errors like SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data<br><br></div>We essentially want to use the viaroute service, so our URL is something like that : "htttp://localhost:5000/viaroute?loc=a,b&loc=c,d" with a,b, c and d random float numbers.<br><br></div><div>Has anyone ever tried to run some customized tests on OSRM, with any Web language, and if so can he give me some tricks of how he succeeded to get the JSON ouptut where he wanted?<br><br></div><div>To be clearer of how I proceeded in AngularJS, here the code of my app.js : <br>var app = angular.module('clientOSRM', ['ngResource']);<br><br>app.controller('appController', ['$scope','$http', 'appServices', function ($scope,$http, appServices) {<br>    //Initialisation de notre input, sa valeur sera stockée en instantané dans cette variable (ng-model)<br>    $scope.valueInput1 = "47.3654647,0.6822917";<br>    $scope.valueInput2 = "47.3905003,0.6920979";<br><br><br>    var getItineraryParams = function () {<br>        return {<br>        start: $scope.valueInput1,<br>        end: $scope.valueInput2<br>        //start: "47.3654647,0.6822917",<br>        //end: "47.3905003,0.6920979"<br>            //start: "a,b",<br>            //end: "c,d"<br>        }<br>    };<br><br>    //Une fonction accessible que dans ce controleur (mot clé var)<br>    var getItinerary = function () {<br>        appServices.osrm.get(getItineraryParams(),<br>            function (itinerary) {<br>        alert("Succes : "+typeof itinerary);<br>                console.log(itinerary);<br>            },<br>            function (error) {<br>        alert("erreur : "+typeof error+"; status : "+error.status);<br>                console.log(error);<br>            }<br>        );<br>    /*$http.jsonp("<a href="http://localhost:5000/viaroute?loc=47.3654647,0.6822917&loc=47.3905003,0.6920979&alt=false&geometry=false&output=json" target="_blank">http://localhost:5000/viaroute?loc=47.3654647,0.6822917&loc=47.3905003,0.6920979&alt=false&geometry=false&output=json</a>")<br>    .success(function(data, status, headers, config) {<br>        console.log(data);<br>      }).<br>      error(function(data, status, headers, config) {<br>        console.log(data);<br>      });*/<br>    <br>    };<br><br>    //Une fonction accessible depuis la vue<br>    //Fonction appelée à l'envoi du formulaire (balise ng-submit dans <form>)<br>    $scope.submit = function () {<br>        //On peut récupérer la valeur de notre input !<br>        //console.log($scope.valueInput1);<br>        getItinerary();<br>    };<br>}]);<br><br>app.run(function ($rootScope) {<br><br>    $rootScope.safeApply = function (fn) {<br>        var phase = $rootScope.$$phase;<br>        if (phase === '$apply' || phase === '$digest') {<br>            if (fn && (typeof(fn) === 'function')) {<br>                fn();<br>            }<br>        } else {<br>            this.$apply(fn);<br>        }<br>    };<br><br>});<br><br></div><div>and also the appServices.js code :<br>app.factory('appServices', function ($resource) {<br><br>    return {<br>        osrm: $resource("", {}, {<br>            'get': {<br>                method: 'GET',<br>                params: {start: '@start', end: '@end'},<br>                isArray:true,<br>                url: "<a href="http://localhost:5000/viaroute?loc=:start&loc=:end&alt=false&geometry=false" target="_blank">http://localhost:5000/viaroute?loc=:start&loc=:end&alt=false&geometry=false</a>"<br>            }<br>        })<br>    };<br>});<br><br></div><div>In the getItinerary function in app.js, the error function (the 3rd parameter) is always triggered even with a HTTP status code '200 OK' of the request.<br><br></div><div>Any ideas where it could go wrong?<br><br></div><div>Thanks in advance.<br></div><div><div><br><br></div></div></div>
<br></div></div>_______________________________________________<br>
OSRM-talk mailing list<br>
<a href="mailto:OSRM-talk@openstreetmap.org" target="_blank">OSRM-talk@openstreetmap.org</a><br>
<a href="https://lists.openstreetmap.org/listinfo/osrm-talk" target="_blank">https://lists.openstreetmap.org/listinfo/osrm-talk</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
OSRM-talk mailing list<br>
<a href="mailto:OSRM-talk@openstreetmap.org">OSRM-talk@openstreetmap.org</a><br>
<a href="https://lists.openstreetmap.org/listinfo/osrm-talk" target="_blank">https://lists.openstreetmap.org/listinfo/osrm-talk</a><br>
<br></blockquote></div><br></div>