Jump to content

[SOLVED] Add Google Driving Directions? Too Complicated?


JTapp

Recommended Posts

I've got a database that lists a variety of addresses and the database includes a text field for driving directions.

 

Has anybody taken database addresses and have a table return a link to Google's driving directions?

 

Thanks in advance for your time!

Link to comment
Share on other sites

<?php
$starting_address = "1600 Pennsylvania Avenue NW Washington, DC";
$ending_address = "1500 Orange Avenue Coronado, CA";
echo <<<END


								<form name="form1">

	Enter your address:
	<!-- input field where the user can enter the source address-->
	<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="$starting_address" />
	<br>
	<!-- html button with a javascript function attached to it to show the directions in the iframe-->
	<INPUT value="Get Directions" TYPE="SUBMIT" onclick="javascript:GetDirections();return false;">
	<BR>
	<BR>		
	<!-- the iframe to show the directions, this is invisible when the page first loads, since the source attribute is empty  -->

	<iframe id="mapframe" name="mapframe" src=""  frameborder="0" width="640px" height="480px">
	</iframe>			
</form>

<script language="javascript">			
	function GetDirections()
	{				
		var SourceAdress = 'saddr=';
		var DestinationAddress = 'daddr=$ending_address'; //hardcoded value for the destination address
		var Url = '';

		//read out source adress from the input field
		SourceAdress += document.form1.saddr.value;	
		//form the url 
		Url = 'http://maps.google.com/maps?' + SourceAdress + '&' + DestinationAddress; // + '&output=html';	

		//open url in iframe
		frames['mapframe'].location.href = Url;			

		//you can use the line below to show the directions in a popup window, don;t forget to comment out the line above... 
		//window.open(Url,'directions','width=1024,height=768,scrollbars=yes,toolbar=no,location=no, resizable=no'); 			
	}

</script>
					  </div>
			 </div>
END;
?>

A rip-off of someones javascript, adding the PHP touch.

Link to comment
Share on other sites

Actually - my situation is I've got about 300 addresses - for the sake of explanation, let's just say I have a company directory of 300 companies and a query that reports company pages.  A company page would outline all sorts of company specific data.  Within that data is an address, city, state, zip field. 

 

I'm wanting to pull the address, city, state, zip from the database and then have a button or a link that says 'click here for driving directions'.  I don't mind sending them to Google to type in their starting address, but the bigger issue (I think) with the code you provided is that the ending address always changes.  Hope this makes sense..

Link to comment
Share on other sites

Simple solution:

<?php
while ($row = mysql_fetch_assoc($query_result_var)){
$starting_address = $_POST['starting_address'];
$ending_address = $row['address'];
print "<a href='http://maps.google.com/maps?saddr=".$starting_address."&daddr=".$ending_address."&output=html'>Link</a>";
}

It was all there in my original code. Just had to decode a bit of it.

Link to comment
Share on other sites

jonsjava - do you have a minute to look at my code? 

I've tried to add what you gave me, but I'm afraid it  seems to interfere with my existing mysql_fetch_array..  My query is already kind of complicated..

 

The fields suppling the address would be:  strLodgeMeetingPlace, strLodgeLocationCity, strLodgeLocationState, strLodgeLocationZip

 

$id = $_GET['id'];

$query = mysql_query("SELECT a.strLodgeName, a.intLodgeNumber, a.intDistrictID, a.strLodgeWEB, a.strLodgeCounty, a.dtChartered, a.strLodgeMeetingPlace, a.strLodgeLocationCity, a.strLodgeLocationState, a.strLodgeLocationZip, a.strLodgeEmail, a.strLodgePhone, a.strLodgeFax, a.strDrivingDirectons, a.dtMeetingTime, a.strMeetingCodes, a.dtMealTime, a.strFloorSchool, a.strLodgeNews, a.strLodgePhotoPathAndName, b.strOfficerTitle, b.strFirstName, b.strLastName, b.BusinessPhone, b.PersEmail FROM tblLodges a LEFT JOIN tblOfficers b ON a.lngLodgeID = b.lngLodgeID WHERE a.intLodgeNumber=$id GROUP BY a.strLodgeName LIMIT 50")or die(mysql_error());
while ($row = @mysql_fetch_array($query))

{
$variable1=$row["strLodgeName"];
$variable2=$row["intLodgeNumber"];
$variable3=$row["intDistrictID"];
$variable4=$row["strLodgeWEB"];
$variable5=$row["strLodgeCounty"];
$variable6=$row["dtChartered"];
$variable7=$row["strLodgeMeetingPlace"];
$variable8=$row["strLodgeLocationCity"];
$variable9=$row["strLodgeLocationState"];
$variable10=$row["strLodgeLocationZip"];
$variable12=$row["strLodgeEmail"];
$variable13=$row["strLodgePhone"];
$variable14=$row["strLodgeFax"];
$variable15=$row["strDrivingDirectons"];
$variable16=$row["dtMeetingTime"];
$variable17=$row["dtMealTime"];
$variable18=$row["strFloorSchool"];
$variable19=$row["strLodgeNews"];
$variable20=$row["strLodgePhotoPathAndName"];
$variable21=$row["strMeetingCodes"];
//table layout for results

echo "<center>\n";
echo "<p><H3>LODGE DETAILS</H4>\n</p>";
echo "<p><b>Lodge Name:</b> $variable1</p>";
echo "<p><b>Lodge Number:</b> $variable2</p>";
echo "<p><b>District Name:</b> $variable3</p>";
echo "<a href=\"mailto:\"$variable4\">Click Here To Go To The Lodge Website</a>";
echo "<p><b>Lodge County:</b> $variable5</p>";
echo "<p><b>Lodge Chartered On:</b> $variable6</p>";
echo "<p><b>Lodge Address:</b></p>";
echo "<p>$variable7   $variable8</p>";
echo "<p>$variable9, $variable10</p>";
echo "<a href=\"mailto:$variable12\">Click Here To Email The Lodge</a>";
echo "<p><b>Lodge Phone Number:</b> $variable13, <b>Lodge FAX Number:</b> $variable14</p>";
echo "<p><b>Lodge Driving Directions:</b> $variable15</p>";

echo "<p<b>Lodge Lodge Meetings:</b> $variable21</p>";
echo "<p<b>Lodge Lodge Meeting Time:</b> $variable16</p>";
echo "<p><b>Lodge Lodge Meal Time:</b> $variable17</p>";
echo "<p><b>Lodge Floor School:</b> $variable18</p>";
echo "<p><b>Lodge News:</b> $variable19</p>";
echo "<img src='{$row['strLodgePhotoPathAndName']}'>";
echo "</center>\n";
}
?>          
          <hr>
          <p>
            <?php
//query details table begins
$query = mysql_query("SELECT tblLodges.strLodgeName, tblLodges.intLodgeNumber, tblLodges.intDistrictID, tblLodges.strLodgeLocationCity, tblLodges.strLodgeLocationZip, tblLodges.strLodgeCounty, tblOfficers.lngLodgeID, tblOfficers.strOfficerTitle, tblOfficers.strFirstName, tblOfficers.strLastName, tblOfficers.BusinessPhone, tblOfficers.PersEmail FROM tblLodges LEFT JOIN tblOfficers ON tblLodges.lngLodgeID = tblOfficers.lngLodgeID WHERE tblLodges.intLodgeNumber=$id GROUP BY tblOfficers.lngOfficerTitleID LIMIT 0, 50")or die(mysql_error());


echo "<center>\n";
echo "<H2>Roster of Lodge Officers</H2>\n";
echo "<table border='1'>
   <tr>
<th>Lodge Number</th>
<th>Officer Title</th>
<th>Officer First</th>
<th>Officer Last</th>
<th>Officer Email</th>
<th>Officer Phone</th>

</tr>";

if (mysql_num_rows($query)) {
    while ($row = mysql_fetch_array($query)) {
        $variable1=$row["intLodgeNumber"];
        $variable2=$row["strOfficerTitle"];
        $variable3=$row["strFirstName"];
        $variable4=$row["strLastName"];
        $variable5=$row["PersEmail"];
        $variable6=$row["BusinessPhone"];
        
        //table layout for results
        
        print("<tr>");
        echo "<tr align=\"center\" bgcolor=\"#EFEFEF\">\n";
        echo "<td class=\"td_id\">$variable1</td>\n";
        echo "<td class=\"td_id\">$variable2</td>\n";
        echo "<td class=\"td_id\">$variable3</td>\n";
        echo "<td class=\"td_id\">$variable4</td>\n";
        echo "<td class=\"td_id\">$variable5</td>\n";
        echo "<td class=\"td_id\">$variable6</td>\n";
        print("</tr>");
    }
}
?>

Link to comment
Share on other sites

<?php
$id = $_GET['id'];

$query = mysql_query("SELECT a.strLodgeName, a.intLodgeNumber, a.intDistrictID, a.strLodgeWEB, a.strLodgeCounty, a.dtChartered, a.strLodgeMeetingPlace, a.strLodgeLocationCity, a.strLodgeLocationState, a.strLodgeLocationZip, a.strLodgeEmail, a.strLodgePhone, a.strLodgeFax, a.strDrivingDirectons, a.dtMeetingTime, a.strMeetingCodes, a.dtMealTime, a.strFloorSchool, a.strLodgeNews, a.strLodgePhotoPathAndName, b.strOfficerTitle, b.strFirstName, b.strLastName, b.BusinessPhone, b.PersEmail FROM tblLodges a LEFT JOIN tblOfficers b ON a.lngLodgeID = b.lngLodgeID WHERE a.intLodgeNumber=$id GROUP BY a.strLodgeName LIMIT 50")or die(mysql_error());
while ($row = @mysql_fetch_array($query))

{
$variable1=$row["strLodgeName"];
$variable2=$row["intLodgeNumber"];
$variable3=$row["intDistrictID"];
$variable4=$row["strLodgeWEB"];
$variable5=$row["strLodgeCounty"];
$variable6=$row["dtChartered"];
$variable7=$row["strLodgeMeetingPlace"];
$variable8=$row["strLodgeLocationCity"];
$variable9=$row["strLodgeLocationState"];
$variable10=$row["strLodgeLocationZip"];
$variable12=$row["strLodgeEmail"];
$variable13=$row["strLodgePhone"];
$variable14=$row["strLodgeFax"];
$variable15=$row["strDrivingDirectons"];
$variable16=$row["dtMeetingTime"];
$variable17=$row["dtMealTime"];
$variable18=$row["strFloorSchool"];
$variable19=$row["strLodgeNews"];
$variable20=$row["strLodgePhotoPathAndName"];
$variable21=$row["strMeetingCodes"];
//table layout for results

echo "<center>\n";
echo "<p><H3>LODGE DETAILS</H4>\n</p>";
echo "<p><b>Lodge Name:</b> $variable1</p>";
echo "<p><b>Lodge Number:</b> $variable2</p>";
echo "<p><b>District Name:</b> $variable3</p>";
echo "<a href=\"mailto:\"$variable4\">Click Here To Go To The Lodge Website</a>";
echo "<p><b>Lodge County:</b> $variable5</p>";
echo "<p><b>Lodge Chartered On:</b> $variable6</p>";
echo "<p><b>Lodge Address:</b></p>";
echo "<p>$variable7   $variable8</p>";
echo "<p>$variable9, $variable10</p>";
echo "<a href=\"mailto:$variable12\">Click Here To Email The Lodge</a>";
echo "<p><b>Lodge Phone Number:</b> $variable13, <b>Lodge FAX Number:</b> $variable14</p>";
echo "<p><b>Lodge Driving Directions:</b><a href='http://maps.google.com/maps?saddr=&daddr=".$variable15."&output=html' target='_blank'>Link</a></p>";

echo "<p<b>Lodge Lodge Meetings:</b> $variable21</p>";
echo "<p<b>Lodge Lodge Meeting Time:</b> $variable16</p>";
echo "<p><b>Lodge Lodge Meal Time:</b> $variable17</p>";
echo "<p><b>Lodge Floor School:</b> $variable18</p>";
echo "<p><b>Lodge News:</b> $variable19</p>";
echo "<img src='{$row['strLodgePhotoPathAndName']}'>";
echo "</center>\n";
}
?>          
          <hr>
          <p>
            <?php
//query details table begins
$query = mysql_query("SELECT tblLodges.strLodgeName, tblLodges.intLodgeNumber, tblLodges.intDistrictID, tblLodges.strLodgeLocationCity, tblLodges.strLodgeLocationZip, tblLodges.strLodgeCounty, tblOfficers.lngLodgeID, tblOfficers.strOfficerTitle, tblOfficers.strFirstName, tblOfficers.strLastName, tblOfficers.BusinessPhone, tblOfficers.PersEmail FROM tblLodges LEFT JOIN tblOfficers ON tblLodges.lngLodgeID = tblOfficers.lngLodgeID WHERE tblLodges.intLodgeNumber=$id GROUP BY tblOfficers.lngOfficerTitleID LIMIT 0, 50")or die(mysql_error());


echo "<center>\n";
echo "<H2>Roster of Lodge Officers</H2>\n";
echo "<table border='1'>
   <tr>
<th>Lodge Number</th>
<th>Officer Title</th>
<th>Officer First</th>
<th>Officer Last</th>
<th>Officer Email</th>
<th>Officer Phone</th>

</tr>";

if (mysql_num_rows($query)) {
    while ($row = mysql_fetch_array($query)) {
        $variable1=$row["intLodgeNumber"];
        $variable2=$row["strOfficerTitle"];
        $variable3=$row["strFirstName"];
        $variable4=$row["strLastName"];
        $variable5=$row["PersEmail"];
        $variable6=$row["BusinessPhone"];
        
        //table layout for results
        
        print("<tr>");
        echo "<tr align=\"center\" bgcolor=\"#EFEFEF\">\n";
        echo "<td class=\"td_id\">$variable1</td>\n";
        echo "<td class=\"td_id\">$variable2</td>\n";
        echo "<td class=\"td_id\">$variable3</td>\n";
        echo "<td class=\"td_id\">$variable4</td>\n";
        echo "<td class=\"td_id\">$variable5</td>\n";
        echo "<td class=\"td_id\">$variable6</td>\n";
        print("</tr>");
    }
}
?>

Link to comment
Share on other sites

Well - my $variable15 is a real field in the database that is actually empty throughout. 

It was designed to literally type in turn by turn driving directions.  I was hoping to get rid of it completely.

 

That said, the Google map isn't returning anything (says check your spelling).

 

The ending address is a combination of these variables:

$variable7=$row["strLodgeMeetingPlace"];

$variable8=$row["strLodgeLocationCity"];

$variable9=$row["strLodgeLocationState"];

$variable10=$row["strLodgeLocationZip"];

 

I was just playing around trying to get it to work (no luck).

 

Link to comment
Share on other sites

<?php
$id = $_GET['id'];

$query = mysql_query("SELECT a.strLodgeName, a.intLodgeNumber, a.intDistrictID, a.strLodgeWEB, a.strLodgeCounty, a.dtChartered, a.strLodgeMeetingPlace, a.strLodgeLocationCity, a.strLodgeLocationState, a.strLodgeLocationZip, a.strLodgeEmail, a.strLodgePhone, a.strLodgeFax, a.strDrivingDirectons, a.dtMeetingTime, a.strMeetingCodes, a.dtMealTime, a.strFloorSchool, a.strLodgeNews, a.strLodgePhotoPathAndName, b.strOfficerTitle, b.strFirstName, b.strLastName, b.BusinessPhone, b.PersEmail FROM tblLodges a LEFT JOIN tblOfficers b ON a.lngLodgeID = b.lngLodgeID WHERE a.intLodgeNumber=$id GROUP BY a.strLodgeName LIMIT 50")or die(mysql_error());
while ($row = @mysql_fetch_array($query))

{
$variable1=$row["strLodgeName"];
$variable2=$row["intLodgeNumber"];
$variable3=$row["intDistrictID"];
$variable4=$row["strLodgeWEB"];
$variable5=$row["strLodgeCounty"];
$variable6=$row["dtChartered"];
$variable7=$row["strLodgeMeetingPlace"];
$variable8=$row["strLodgeLocationCity"];
$variable9=$row["strLodgeLocationState"];
$variable10=$row["strLodgeLocationZip"];
$variable12=$row["strLodgeEmail"];
$variable13=$row["strLodgePhone"];
$variable14=$row["strLodgeFax"];
$variable15=$row["strDrivingDirectons"];
$variable16=$row["dtMeetingTime"];
$variable17=$row["dtMealTime"];
$variable18=$row["strFloorSchool"];
$variable19=$row["strLodgeNews"];
$variable20=$row["strLodgePhotoPathAndName"];
$variable21=$row["strMeetingCodes"];
//table layout for results

echo "<center>\n";
echo "<p><H3>LODGE DETAILS</H4>\n</p>";
echo "<p><b>Lodge Name:</b> $variable1</p>";
echo "<p><b>Lodge Number:</b> $variable2</p>";
echo "<p><b>District Name:</b> $variable3</p>";
echo "<a href=\"mailto:\"$variable4\">Click Here To Go To The Lodge Website</a>";
echo "<p><b>Lodge County:</b> $variable5</p>";
echo "<p><b>Lodge Chartered On:</b> $variable6</p>";
echo "<p><b>Lodge Address:</b></p>";
echo "<p>$variable7   $variable8</p>";
echo "<p>$variable9, $variable10</p>";
echo "<a href=\"mailto:$variable12\">Click Here To Email The Lodge</a>";
echo "<p><b>Lodge Phone Number:</b> $variable13, <b>Lodge FAX Number:</b> $variable14</p>";
echo "<p><b>Lodge Driving Directions:</b><a href='http://maps.google.com/maps?saddr=&daddr=".$variable17.", ".$variable8.", ".$variable9."' target='_blank'>Link</a></p>";

echo "<p<b>Lodge Lodge Meetings:</b> $variable21</p>";
echo "<p<b>Lodge Lodge Meeting Time:</b> $variable16</p>";
echo "<p><b>Lodge Lodge Meal Time:</b> $variable17</p>";
echo "<p><b>Lodge Floor School:</b> $variable18</p>";
echo "<p><b>Lodge News:</b> $variable19</p>";
echo "<img src='{$row['strLodgePhotoPathAndName']}'>";
echo "</center>\n";
}
?>          
          <hr>
          <p>
            <?php
//query details table begins
$query = mysql_query("SELECT tblLodges.strLodgeName, tblLodges.intLodgeNumber, tblLodges.intDistrictID, tblLodges.strLodgeLocationCity, tblLodges.strLodgeLocationZip, tblLodges.strLodgeCounty, tblOfficers.lngLodgeID, tblOfficers.strOfficerTitle, tblOfficers.strFirstName, tblOfficers.strLastName, tblOfficers.BusinessPhone, tblOfficers.PersEmail FROM tblLodges LEFT JOIN tblOfficers ON tblLodges.lngLodgeID = tblOfficers.lngLodgeID WHERE tblLodges.intLodgeNumber=$id GROUP BY tblOfficers.lngOfficerTitleID LIMIT 0, 50")or die(mysql_error());


echo "<center>\n";
echo "<H2>Roster of Lodge Officers</H2>\n";
echo "<table border='1'>
   <tr>
<th>Lodge Number</th>
<th>Officer Title</th>
<th>Officer First</th>
<th>Officer Last</th>
<th>Officer Email</th>
<th>Officer Phone</th>

</tr>";

if (mysql_num_rows($query)) {
    while ($row = mysql_fetch_array($query)) {
        $variable1=$row["intLodgeNumber"];
        $variable2=$row["strOfficerTitle"];
        $variable3=$row["strFirstName"];
        $variable4=$row["strLastName"];
        $variable5=$row["PersEmail"];
        $variable6=$row["BusinessPhone"];
        
        //table layout for results
        
        print("<tr>");
        echo "<tr align=\"center\" bgcolor=\"#EFEFEF\">\n";
        echo "<td class=\"td_id\">$variable1</td>\n";
        echo "<td class=\"td_id\">$variable2</td>\n";
        echo "<td class=\"td_id\">$variable3</td>\n";
        echo "<td class=\"td_id\">$variable4</td>\n";
        echo "<td class=\"td_id\">$variable5</td>\n";
        echo "<td class=\"td_id\">$variable6</td>\n";
        print("</tr>");
    }
}
?>

I recombined it so that it's just "Location, City, State". It should work now

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.