I have successfully implemented a routing system at my website using the cloudmade API. I also want to do the same with the OSRM routing system (https://github.com/DennisOSRM/Project-OSRM) but I'm having some trouble getting the OSRM json output.
Here are examples of retrieving json from the cloudmade API:
Using $.ajax - http://jsfiddle.net/mayooresan/FhfVW/2/
$(function () {
$("#getJSON").click(function () {
var url = "http://routes.cloudmade.com/c6f2762bfe00414f822a9dec443569f5/api/0.3/51.500,0.100,51.500,0.1001/car.js";
$.ajax({
async: false,
dataType: "jsonp",
url: url,
success: function (data) {
test = data.route_geometry;
alert(test);
}
});
});
});
Using $.getJSON - http://jsfiddle.net/V3qgZ/72/
$(function () {
$("#getJSON").click(function () {
$.getJSON("http://routes.cloudmade.com/c6f2762bfe00414f822a9dec443569f5/api/0.3/51.500,0.100,51.500,0.1001/car.js?callback=?", function (data) {
var test = data.route_geometry;
alert(test);
});
});
});
The server API for OSRM is located here: https://github.com/DennisOSRM/Project-OSRM/wiki/Server-api (The server location for queries is located at http://router.project-osrm.org).
Putting the URL with the same coordinates used above (http://router.project-osrm.org/viaroute?loc=51.500,0.100&loc=51.500,0.1001) into the browser retrieves a json file. But no matter what I have tried using this with $.getJSON or $.ajax - using callbacks, setting datatypes, I cannot get the json data and it is driving me nuts! And I'm sure it's possible because it is documented in the API.