Jump to content

Recommended Posts

here's a simple script to generate driving directions. I'm not sure it will help, but, hopefully it will:

<?php
$name = "John Doe";
$address = "1600 Pennsylvania Ave NW Washington DC";
?>
<h3>Directions to <?php print $name; ?></h3>
								<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="" />
	<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=<?php print $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';	
		window.open(Url,'directions','width=1024,height=768,scrollbars=yes,toolbar=no,location=no, resizable=no'); 			
	}

</script>
					  </div>

Link to comment
https://forums.phpfreaks.com/topic/155369-php-and-google-maps/#findComment-817449
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.