Jump to content

PHP and google maps


Yammyguy

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.