views:

1401

answers:

1

I've worked with google maps before, but when implementing it, I've never found any documentation on how to get the exact distance between 2 given locations via Javascript or PHP.

1) It has to be the exact same distance shown on maps, not that formula that gives you the distance in a straight line from one geopoint to the other.

2) It has to be either PHP or Javascript

3) It has to be Google maps, not virtual earth or anything similar.

Best thing I've come up with is sending a HTTP_GET request to google maps using a long URL with variables, which then returns a 200 code plus the HTML for the website. The distance is in there somewhere, just need to filter.

But that's resources intensive and load heavy.

Does anybody know of a better way?

EDIT: this is the function I'm talking about. The DLL isn't included in the regular zip file for windows, I found it as a part of the WAMPserver software.

+3  A: 

This posting gives a way and a warning.

To break it down you use google maps to query a URL like this

http://maps.google.com/maps?q=from+A+to+B&output=kml

and then you view the data retrieved from that url (in kml format) and look at the placemark tags (run it through simplexml) each placemark tag will have a description child that will have a text description of the next step in the route from A to B.

Also mentioned in the article is that by using this method you are bound by the google maps T&C which states

Also, you may not use Google Maps in a manner which gives you or any other person access to mass downloads or bulk feeds of numerical latitude and longitude coordinates.

So you may want to keep that in mind.

linead
Imagine a website that allows you to drop of your baby somewhere while you go out with your partner. Babysitting.The distance you'll want to drive to drop of your child is different for everyone, so they need to enter a maximum distance in to a searchfield and I can then create a list of site-members who fall within that distance by car.The database contains no numerical values, only streetname and housenumber.
WebDevHobo
linead