tags:

views:

408

answers:

5

Is there a service that will give me the driving distance between two addresses? Apparently Google Maps API requires you to display a map, which I don't want to do (on that particular page), and I'd like to just snag the data and save it to my DB after a user submits a form, rather than waiting for JS to do it's thing.


If it's relevant, this is going into a Django app. I discovered that CloudMade offers a Python API, which is nice, except their latest dev release has a bug in it (can't use the API object), but more importantly, it's support for Canada is awful (couldn't find directions from any major city around here!).

+1  A: 

There are free services out there, but the quality of the data may be questionable/non-existent in areas. Be aware of licences on the data too, storing in your own DB may be a breach.

http://openrouteservice.org/

Jonathan
Is that service for the UK only? Doesn't seem to recognize any Canadian locations...
Mark
Europe data.More info: http://wiki.openstreetmap.org/index.php/OpenRouteService. Plus other examples, http://wiki.openstreetmap.org/wiki/YOURS, http://www.yournavigation.org/
Jonathan
+2  A: 

Would it be possible to use Google Maps GDirections object? This can return the textual directions instead of the map overlay if called with a div object. From there you can use the getDistance (or getDuration) functions. You can always use an invisible div for the returns if you don't want anything to be displayed on the page.

Start here
http://code.google.com/apis/maps/documentation/examples/directions-advanced.html
http://code.google.com/apis/maps/documentation/reference.html#GDirections

And use this sample code

   var map;
    var directionsPanel;
    var directions;

    function initialize() {
      directionsPanel = document.getElementById("route");
      directions = new GDirections(null, directionsPanel);
      GEvent.addListener(directions , "load", onGDirectionsLoad);
      directions.load("from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)");
    }

    function onGDirectionsLoad(){ 
      alert(directions.getDistance().html);
    }
ktharsis
"Google Maps API requires you to display a map, which I don't want to do (on that particular page), and I'd like to just snag the data and save it to my DB after a user submits a form, rather than waiting for JS to do it's thing." -- Requires, as in, their policy dictates. It's not a programmatic problem, it's a legal issue. Secondly, I'd prefer a non-JS solution as I indicated. Thanks though.
Mark
Well the "requires" map you should check into. Their API docs and online examples clearly explain how to NOT show the map for customers that don't want it (the null param in the GDirections constructor).As for calling it from the server instead of the client - just write the JS and call it from the server in a web control (not sure what that is in Django) and parse the return directly. Puts the traffic on your server instead of the client. Not sure if you can do that with a direct call though - probably have to use JS in a server web control.
ktharsis
Can't remember where I read it's against their ToS now. Putting the JS into a web control on my shared server might be tricky...
Mark
Check it out. I saw where you aren't supposed to save any data for offline use (which would kill your saving into a database idea) but maybe there are exceptions or loopholes. Did you try the other "big" ones? MS/Bing or MapQuest? MapQuest has server side libraries (C++/C#/Java) but I don't know their ToS.
ktharsis
For clarification on usage of the Google Maps API, ask over on the official Group: http://groups.google.com/group/Google-Maps-API
artlung
+2  A: 

Take a look at Navteq. I used their service in developing a driving directions application about 5 years ago, and got good results. Can't speak for them lately though. I believe the best URL is Navteq Routing Service

Chris Mo
It's not free :(
Mark
correct, its not - didn't know that was a requirement... sorry
Chris Mo
I guess I didn't specify. Too early in the project to start dishing out $$$ for "nice to haves".
Mark
+1  A: 

MapQuest's Directions API is HTTP Querystring based (I'm not sure if it's entirely RESTful). Can get XML or JSON response. Just need to send it an HTTP GET Request.

http://developer.mapquest.com/web/products/directions-ws

Use the "distance" response parameter.

el chief
Wish I could switch the check over to you...this is exactly what I was looking for!
Mark
just helpin' a fellow Canuck out!
el chief
+1  A: 

You can use the new Google Directions API directly, without using any javascript. http://code.google.com/apis/maps/documentation/directions/

illarra
When was this released? Exactly what I was looking for!
Mark
It was released at Google I/O 2010: http://googlegeodevelopers.blogspot.com/2010/05/directions-web-service-arrives-at.html
illarra