Scripts

Google Routebeschrijving

Dit script bevat vooral HTML en JAVASCRIPT Dit script had ik nodig voor een website waar ik aan heb gewerkt. Dit script is makkelijk in gebruik en heeft vele mogelijk heden. 1. Bij het eerste script moet je de locatie van en naar zelf invullen. (Route1.php) 2. Bij het tweede script is de locatie naar al ingevuld. (Route2.php) 3. Bij het derde script kun je kiezen uit meerdere locaties. (Route3.php) Het uitvoeren van het script word in een pop-up gedaan dat vond ik makkelijk, overzichtelijk en handig als mensen het willen printen. (Popup.php) Het laatste is natuurlijk het aanroepen van de pop-up functie in javascript. (Popup.js)

google-routebeschrijving
Route1.php
[code]
<form action="#" onSubmit="GO('popup.php?from='+this.adres.value+this.space.value+this.postcode.value+this.space.value+this.plaats.value+'&to='+this.toadres.value+this.space.value+this.topostcode.value+this.space.value+this.toplaats.value+'&locale='+this.locale.value); return false">
<!-- SPACE -->
<input type="hidden" id="space" name="space" value=", " />
<!-- /SPACE -->
    <table>
    	<tr>
			<td style="height:20px;" colspan="3"><strong>Van: </strong></td>
        </tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Adres: </td>
			<td><input type="text" size="25" id="adres" name="adres" onfocus="if(this.value=='Straatnaam'){this.value='';}" onblur="if(this.value==''){this.value='Straatnaam';}" value="Straatnaam"/></td>
		</tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Postcode: </td>
			<td><input type="text" size="25" id="postcode" name="postcode" onfocus="if(this.value=='Postcode'){this.value='';}" onblur="if(this.value==''){this.value='Postcode';}" value="Postcode"/></td>
		</tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Woonplaats: </td>
			<td><input type="text" size="25" id="plaats" name="plaats" onfocus="if(this.value=='Woonplaats'){this.value='';}" onblur="if(this.value==''){this.value='Woonplaats';}" value="Woonplaats"/></td>
		</tr>
		<tr>
			<td style="height:20px;" colspan="3"><strong>Naar: </strong></td>
        </tr>
        <tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Adres: </td>
			<td><input type="text" size="25" id="toadres" name="toadres" onfocus="if(this.value=='Straatnaam'){this.value='';}" onblur="if(this.value==''){this.value='Straatnaam';}" value="Straatnaam"/></td>
		</tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Postcode: </td>
			<td><input type="text" size="25" id="topostcode" name="topostcode" onfocus="if(this.value=='Postcode'){this.value='';}" onblur="if(this.value==''){this.value='Postcode';}" value="Postcode"/></td>
		</tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Woonplaats: </td>
			<td><input type="text" size="25" id="toplaats" name="toplaats" onfocus="if(this.value=='Woonplaats'){this.value='';}" onblur="if(this.value==''){this.value='Woonplaats';}" value="Woonplaats"/></td>
		</tr>
        
		<tr>
			<td style="height:20px;" colspan="3"><input id="locale" name="locale" type="hidden" value="nl_NL" /></td>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td colspan="2" align="center"><input name="submit" type="submit" value="Routebeschrijving" /></td>
		</tr>
	</table>
</form>
[/code]
Route2.php
[code]
<form action="#" onSubmit="GO('popup.php?from='+this.adres.value+this.space.value+this.postcode.value+this.space.value+this.plaats.value+'&to='+this.to.value+'&locale='+this.locale.value); return false">
<!-- SPACE -->
<input type="hidden" id="space" name="space" value=", " />
<!-- /SPACE -->
    <table>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Adres: </td>
			<td><input type="text" size="25" id="adres" name="adres" onfocus="if(this.value=='Straatnaam'){this.value='';}" onblur="if(this.value==''){this.value='Straatnaam';}" value="Straatnaam"/></td>
		</tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Postcode: </td>
			<td><input type="text" size="25" id="postcode" name="postcode" onfocus="if(this.value=='Postcode'){this.value='';}" onblur="if(this.value==''){this.value='Postcode';}" value="Postcode"/></td>
		</tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Woonplaats: </td>
			<td><input type="text" size="25" id="plaats" name="plaats" onfocus="if(this.value=='Woonplaats'){this.value='';}" onblur="if(this.value==''){this.value='Woonplaats';}" value="Woonplaats"/></td>
		</tr>

		<tr>
			<td><input type="hidden" size="25" id="toAddress" name="to" value="Straatnaam + Huisnummer, Postcode, Plaats" /></td>
        </tr>
        
		<tr>
			<td colspan="3" height="20"><input id="locale" name="locale" type="hidden" value="nl_NL" /></td>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td colspan="2" align="center"><input name="submit" type="submit" value="Routebescrijving" /></td>
		</tr>
	</table>
</form>
[/code]
Route3.php
[code]
<form action="#" onSubmit="GO('popup.php?from='+this.adres.value+this.space.value+this.postcode.value+this.space.value+this.plaats.value+'&to='+this.to.value+'&locale='+this.locale.value); return false">
<!-- SPACE -->
<input type="hidden" id="space" name="space" value=", " />
<!-- /SPACE -->
    <table>
    	<tr>
			<td style="height:20px;" colspan="3"><strong>Van: </strong></td>
        </tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Adres: </td>
			<td><input type="text" size="25" id="adres" name="adres" onfocus="if(this.value=='Straatnaam'){this.value='';}" onblur="if(this.value==''){this.value='Straatnaam';}" value="Straatnaam"/></td>
		</tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Postcode: </td>
			<td><input type="text" size="25" id="postcode" name="postcode" onfocus="if(this.value=='Postcode'){this.value='';}" onblur="if(this.value==''){this.value='Postcode';}" value="Postcode"/></td>
		</tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
			<td>Woonplaats: </td>
			<td><input type="text" size="25" id="plaats" name="plaats" onfocus="if(this.value=='Woonplaats'){this.value='';}" onblur="if(this.value==''){this.value='Woonplaats';}" value="Woonplaats"/></td>
		</tr>
        
		<tr>
			<td style="height:20px;" colspan="3"><strong>Naar: </strong></td>
        </tr>
		<tr>
        	<td style="width:50px; height:20px;"></td>
            <td>Locatie: </td>
			<td>
            	<select name="to" id="toAdress">
					<option value="Straatnaam + Huisnummer, Postcode, Plaats">Naam Locatie 1</option>
					<option value="Straatnaam + Huisnummer, Postcode, Plaats">Naam Locatie 2</option>
				</select>
             </td>
        </tr>
        
		<tr>
			<td style="height:20px;" colspan="3"><input id="locale" name="locale" type="hidden" value="nl_NL" /></td>
		<tr>
			<td style="width:50px; height:20px;"></td>
            <td colspan="2" align="center"><input name="submit" type="submit" value="Routebeschrijving" /></td>
		</tr>
	</table>
</form>
[/code]
Popup.php
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Routebeschrijving</title>
</head>
<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=abcdefg&sensor=true"></script>


<script type="text/javascript">
//<![CDATA[
    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

    function load() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map"));

        geocoder = new GClientGeocoder();
        if (geocoder) {
            geocoder.getLatLng(
			  "[code]<?=$_GET[to]?>[/code]",
              function(point) {
                if (!point) {
                  alert("[code]<?=$_GET[to]?>[/code]" + " niet gevonden");
                } else {
                  map.setCenter(point, 13);
                  //var marker = new GMarker(point);
                  //map.addOverlay(marker);
				  map.setUIToDefault();
                 // marker.openInfoWindowHtml("<b>Tsja</b><br>laatje 3<br> Bergentheim");
                }
              }
            );
        }

        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        setDirections("The Netherlands", "Hoogeveen", "nl_NL");
		
      }
    }
    
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
        checkAddress(fromAddress);
    }
    
    function checkAddress(adres){
        geocoder2 = new GClientGeocoder();
        if (geocoder2) {
            geocoder2.getLatLng(
              adres,
              function(point) {
                if (!point) {
                  alert(adres + " is geen geldig adres. Voer als volgt in: Straat + huisnr, postcode, plaats");
                }
              }
            );
        }
    }

    function handleErrors(){
       if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
         alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.nError code: " + gdir.getStatus().code);
       else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
         alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.n Error code: " + gdir.getStatus().code);
      
       else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
         alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.n Error code: " + gdir.getStatus().code);

    //   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
    //     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.n Error code: " + gdir.getStatus().code);
        
       else if (gdir.getStatus().code == G_GEO_BAD_KEY)
         alert("The given key is either invalid or does not match the domain for which it was given. n Error code: " + gdir.getStatus().code);

       else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
         alert("A directions request could not be successfully parsed.n Error code: " + gdir.getStatus().code);
        
       else alert("An unknown error occurred.");
      
    }                        



//]]>

<!--
function timeout(){
	setDirections("[code]<?=$_GET[from]?>[/code]", "[code]<?=$_GET[to]?>[/code]", "[code]<?=$_GET[locale]?>[/code]");
}
setTimeout("timeout()",1000);
-->
</script>
</head>
<body onLoad="load();" onUnload="GUnload()">
<table border="0">
<tr>
    <td style="vertical-align:top; padding:5px;"><div id="map" style="width: 405px; height: 400px; float:left;"></div></td>
</tr><tr>
    <td style="vertical-align:top;"><div id="directions" style="width: 405px; float:right; padding:5px;"></div></td>
</tr>
</table>
</body>
</html>
[/code]
Popup.js
[code]
function PopUpWindow(filename,windowname,toolbar,location,directories,status,menubar,scrollbars,resizable,copyhistory,_width,_height)
 {
  window.open(filename,windowname,"toolbar="+toolbar+",location="+location+",directories="+directories+",status="+status+",menubar="+menubar+",scrollbars="+scrollbars+",resizable="+resizable+",copyhistory="+copyhistory+",width="+_width+",height="+_height+"");
 }
function GO(url) {PopUpWindow(url,'Routebeschrijving',0,0,0,1,0,1,0,0,550,600)}
[/code]

Reacties

0
Nog geen reacties.