views:

1183

answers:

2

Google maps has a function that lets you retreive the distance between two points: getDistance(), of the GDirections class.

Now, this is Javascript, so it'll only be able to calculate once the page has loaded.

My search form however, has the ability to indicate what's the maximum distance you want between yourself and another person and based on that, a list of search results has to be provided.

Since I can't use this function in PHP, is there another way for me to calculate the distance between 2 points on the earth? By giving up the street, postal code and city name, just like what Google maps needs.

+1  A: 

This page has a list of google maps parameters for use in http connection. By specifying the output paramter you can choose to give back kml files or similar and can be used in any lanuage that can make http connections.

Tim Matthews
okay, but what PHP functions and/or classes do I use in combination with this?
Vordreller
+1  A: 

Looks like you want to calculate a Great Circle Distance

Formulas have been discussed here on stackoverflow before.

A point on earth is defined by it's latitude and longitude. If you want to calculate the distance between 2 points on earth by giving up the street, postal code and city name, you will need geo-referene data.

This data is available for free on the internet, but the accuracy and availability differ greatly from region to region. (USA data is of good quality, data for Kenia for example will be harder to come by)

So to answer your question:
Yes, there are other ways to calculate what you want. But they require more work/are more complex than just querying the google API.
You might want tot read: Creating a Store Locator with PHP, MySQL & Google Maps

Hope this points you into the right direction.

Jacco
I've just finished reading, and I think it solves my problem, but I'm not sure. What I would prefer is that my PHP page would somehow contact the google maps servers, a starting point and a whole bunch of end points, and then return to me the distances. Based on that, I can populate a search result
Vordreller
I you think it's a helpfull answer, you might as well vote it up.
Jacco