Post samen met Google API
Ik heb weer wat dingen teruggezet om het weer "werkend" te krijgen. Ik heb GET ook weer even bovenin staan om te zien of de kilometers en de plaatsen wel binnen komen.
Zoals onderstaande code komt de postcode en de plaats met GET weer binnen, maar het aantal passagiers niet.
Verander ik -----> <form action="" onsubmit="showLocation(); return false;">
in
<form name="pricecalculator" action="" method="post"> dan is het andersom, wel aantal passagiers maar geen info vua Google met Get.
Verder heb ik veel dingen die je doorgaf gecombeneerd in allerlij vormen maar niets werkt.
Dit is de code nu:
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link type="text/css" rel="stylesheet" href="style.css" media="screen" />
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAgV13-t4t3STpZlalXFAmzxQWUOUdy4en180hY4LdqgARW0NSBBR4VptnbNX5MzDRXExbmWRMpnIwGA" type="text/javascript"></script>
<!-- According to the Google Maps API Terms of Service you are required display a Google map when using the Google Maps API. see: http://code.google.com/apis/maps/terms.html -->
</head>
<body>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$pkVervoermiddelId = $_POST["pkVervoermiddelId"];
echo 'Aantal personen is: ' .$pkVervoermiddelId ;
}
if(!empty($_GET['km'])){
//if($_SERVER['REQUEST_METHOD'] == "POST"){
$km = $_GET['km'];
$Adres1 = $_GET['adres1'];
$Adres2 = $_GET['adres2'];
$prijs = $km * 2;
echo "De afstand is $km kilometer";
echo "<br/> Adres 1 : $Adres1 ";
echo "<br/> Adres 2 : $Adres2 ";
}
?>
if($_SERVER["REQUEST_METHOD"] == "POST"){
$pkVervoermiddelId = $_POST["pkVervoermiddelId"];
echo 'Aantal personen is: ' .$pkVervoermiddelId ;
}
if(!empty($_GET['km'])){
//if($_SERVER['REQUEST_METHOD'] == "POST"){
$km = $_GET['km'];
$Adres1 = $_GET['adres1'];
$Adres2 = $_GET['adres2'];
$prijs = $km * 2;
echo "De afstand is $km kilometer";
echo "<br/> Adres 1 : $Adres1 ";
echo "<br/> Adres 2 : $Adres2 ";
}
?>
<script type="text/javascript">
var geocoder, location1, location2, gDir;
function initialize() {
geocoder = new GClientGeocoder();
gDir = new GDirections();
GEvent.addListener(gDir, "load", function() {
var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
var km = Math.round(drivingDistanceKilometers + 0.5)
if (km > 0 ) {
window.location.href = "http://taxi2me.nl/ROUTE/postcode2.php?km=" + km + "&adres1=" + location1.address + "&adres2=" + location2.address;
}
document.getElementById('results').innerHTML = '<strong>Address 1: </strong>' + location1.address + '<br /><strong>Address 2: </strong>' + location2.address + '<br /><strong>Afstand: </strong>' + drivingDistanceKilometers + ' kilometers';
}); }
function showLocation() {
geocoder.getLocations(document.forms[0].address1.value, function (response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode the first address");
}
else
{
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.getLocations(document.forms[0].address2.value, function (response) {
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode the second address");
}
else
{
location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
gDir.load('from: ' + location1.address + ' to: ' + location2.address);
}});
}});}
</script>
<body onload="initialize()">
<form action="" onsubmit="showLocation(); return false;">
<div>
<label for="postcode">Aantal personen:</label>
<select name="pkVervoermiddelId">
<option value="0">- Maak een keuze - </option>
<option value="1" #NrPers1# >1 passagiers</option>
<option value="2" #NrPers2# >2 passagiers</option>
<option value="3" #NrPers3# >3 passagiers</option>
<option value="4" #NrPers4# >4 passagiers</option>
<option value="5" #NrPers5# >5 passagiers</option>
<option value="6" #NrPers6# >6 passagiers</option>
<option value="7" #NrPers7# >7 passagiers</option>
<option value="8" #NrPers8# >8 passagiers</option>
</select>
<input id="postcode" type="text" name="address1" value="1326 NA"/><br />
<input type="hidden" name="address2" value="1118 AX" />
<input type="submit" value="Bereken Prijs" />
</div>
</form>
</body>
</html>