I used this query URL
,which is given in the answer to this question. But after I tried it, it doesn’t work with coordinates. It works with address names tho. I guess I could use google’s geocoding to get the addresses first. But I wonder if there is another way to get the walking distance between two coordinates?
My New Answer 🙂
Use the Google Directions API.
It should be possible to make a request to
http://maps.google.com/maps/api/directions/<json|xml>?<params>and specifying the coords asoriginanddestinationparameter.I briefly tried it but it returned no results. Along their docs it should work, but they don’t explain in detail how to specify latitude and longitude. But they say it’s possible. Quote:Nevertheless, this should get you started. I would suggest going with the JSON output format. It’s much simpler to parse and should use up less bandwidth (it’s less verbose as XML).
It works: Here’s an example URL:
http://maps.google.com/maps/api/directions/json?origin=49.75332,6.50322&destination=49.71482,6.49944&mode=walking&sensor=falseMy Previous Answer
The straight line distance can easily be determined using the Haversine formula. If you retrieve the route from Google, then you could calculate the distance of each segment and sum them up.
A while back, I wrote down the (well-known) algorithm (Haversine) in a blog post (python and pl/sql)
Here’s the copy of the python code:
Translating this to Java should be trivial.