0

Possible Duplicates:
Using PHP and google Maps Api to work out distance between 2 post codes (UK)
Google Maps API: get two locations distance and plot on map

I made a interface where a user can insert start and finish address and after submitting I want to get the latitude and longitude of the both addresses and then calculate the distance between them. I have pasted the code below so far I have done:

<html>
<head>
</head>
<body>
    <form method="post" action ="gMap.php?showDistance=1" >
        <table>
            <tr><td>Start:</td><td><input id="start" type="text"  name='start'/> </td></tr></br>
            <tr><td>Finish:</td><td><input id="finish" type="text" name='finish'/></td></tr></br>
            <tr><td></td><td><input type="submit" value="Calculate Distance" /></td></tr></br>
        </table>
    </form>
<!--  
<br/><br/>
<div id="map" style="width: 500px; height: 350px"></div>
<div id="results" style="width: 500px;"></div>
-->
</body>
</body> 
</html>
<?php
if(isset($_GET['showDistance'])) {

    if(!empty($_POST['start'])&& !empty($_POST['finish'])){
    $start='';
    $finish='';
    $start=$_POST['start'];
    $finish=$_POST['finish'];

    // I want to send start address via this url;
    $startUrl = 'http://maps.google.com/maps/api.............';
    $startData = @file_get_contents($startUrl);

    // I want to send finish address via this url;
    $finishUrl = 'http://maps.google.com/maps/api............';
    $finishData = @file_get_contents($finishUrl);

    $startResult = explode(",", $startData);
    $finishResult = explode(",", $finishData);

    echo "Information about start address:"."<br/>";
    echo $startResult[0]."<br/>"; // status code
    echo $startResult[1]."<br/>"; // accuracy
    echo $startResult[2]."<br/>"; // latitude
    echo $startResult[3]."<br/>";; // longitude

    echo "Information about finish address:"."<br/>";

    echo $finishResult[0]."<br/>"; // status code
    echo $finishResult[1]."<br/>"; // accuracy
    echo $finishResult[2]."<br/>"; // latitude
    echo $finishResult[3]."<br/>";; // longitude

    } else {
    echo "You forget to insert address";
    }
}  
?>

Now the problem I am facing is that I don't know how use the google map api url to get the required information from google map. $startUrl and $finishUrl are the two variable of my concern. By the way I haven't written the code for distance calculation because I yet to get the respected latitude and longitude values.

Cœur
  • 37,241
  • 25
  • 195
  • 267
minhaz
  • 503
  • 1
  • 5
  • 12
  • Do you want to calculate distance using the Google Maps API **or** PHP? (you can do it with either, but it would be absurd to use both). – Marcelo Nov 25 '12 at 08:06
  • I want to do it using google maps api but want to use php to process is further @Marcelo – minhaz Nov 25 '12 at 08:12
  • This is about the calculation,but I want to know how can pass the searched addresses through the google maps api url – minhaz Nov 25 '12 at 08:23
  • Your question says "How to calculate the distance..." not "how to pass data between Javascript and PHP" – Marcelo Nov 25 '12 at 08:32

0 Answers0