One of the features of the project I'm currently working on is a
function that will find the driving distance between two points, with
"driving" being the key word. There's numerous utilities that will
find the distance "as the crow flies" (a straight line), but the
client needs to know driving distance. I thought doing it with the
Google or Yahoo Map API, but I found it to be 1) a whole lot of extra
code that really wasn't needed and 2) there was a seemingly simpler
way to get the data. There's a way to get map data directly from
Google Maps without using the Maps API.
For example, if you are doing a search for the driving distance
between New York City, NY (10007) and New Haven, CT (06511) you can
plug in the two ZIP codes (or full addresses) into the following url:
http://maps.google.com/maps?q=from+10007+to+06511&output=kml
which return a .kml file. The .kml extension is an XML format used
with Google Earth. The distance that is returned with the file can be
found in the following code block:
<description>
<![CDATA[Distance: 82 mi (about 1 hour 54 mins)<br/>Map data
©2008 Tele Atlas ]]>
</description>
In older versions of this code, the tags were a bit different but the
data contained in the CDATA (before the <br/> tag) was identical.
Ideally, I'd like to set up a search function where the user types in
two addresses (or chooses them from the database) and then this script
will calculate the driving distance by parsing through the file that
is returned for the text "Distance: ([0-9\.,]) ([a-z\.])".
Does anyone have any ideas how to do this?
Thanks,
Will