Hi I have this code which searches for the sitance between 2 addresses. I have a bit of code that calulates the price from the distance. I am trying to change it to enter the addresses first, then it displays address with the image(Obviousy changing the address on load!) and then if they correct, runs the php script to give the pirce!, all in one page with our reloading. I cant seem to be able to execute the scripts together? Any help really appreciated!!!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API Example: Extraction of Geocoding Data</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA7j_Q-rshuWkc8HyFI4V2HxQYPm-xtd00hTQOC0OXpAMO40FHAxT29dNBGfxqMPq5zwdeiDSHEPL89A" 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: [url]http://code.google.com/apis/maps/terms.html[/url] -->
<script type="text/javascript">
var geocoder, location1, location2;
function initialize() {
geocoder = new GClientGeocoder();
}
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};
calculateDistance();
}
});
}
});
}
function calculateDistance()
{
try
{
var glatlng1 = new GLatLng(location1.lat, location1.lon);
var glatlng2 = new GLatLng(location2.lat, location2.lon);
var miledistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(1);
var kmdistance = (miledistance * 1.609344).toFixed(1);
document.getElementById('results').innerHTML = '<strong>Pickup: </strong>' + location1.address + '<br /><strong>Dropoff: </strong>' + location2.address + '<br /><strong>Distance: </strong>' + miledistance + ' miles (or ' + kmdistance + ' kilometers)';
}
catch (error)
{
alert(error);
}
}
</script>
</head>
<body onload="initialize()">
<form action="#" onsubmit="showLocation(); return false;">
<p>
<input type="text" name="address1" value="Address 1" class="address_input" size="40" />
<input type="text" name="address2" value="Address 2" class="address_input" size="40" />
<input type="submit" name="find" value="Search" />
</p>
</form>
<p id="results"><table cellspacing="0" cellpadding="0" border="0"><tr><td><iframe src="http://www.map-generator.net/extmap.php?name=pickup&address=6%20tredington%20road%2C%20cv57bn&width=500&height=400&maptype=map&zoom=20&hl=en&t=1333378206" width="500" height="400" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe></td></tr><tr><td align="right"><a style="font:8px Arial;text-decoration:none;cursor:default;color:#5C5C5C;" href="http://www.map-generator.net">map-generator.net</a></td></tr></table><!-- Do not change code! --></p>
</body>
</html>
<?
$small = array(5,4,9.5,8,7,5,5,3.8,4,3.5,2.7);
$med = array(6.66,5,11,10.33,7.5,6.66,6.25,4.6,4.5,3.9,3.6);
$large = array(8.33,6,12.5,12.33,8.5,7.66,6.87,5.2,4.9,4.3,4.1);
$dists = array(3,5,10,15,20,30,40,50,80,100,9999999);
if($_GET[lat]!='')
{
$lat = $_GET[lat];
if($_GET[lon]!='')
{
$lon = $_GET[lon];
$url = 'http://maps.googleapis.com/maps/api/directions/json?origin='.$lat.'&waypoints=optimize:false|'.$lon.'&sensor=false';
$res = json_decode(get_html($url),true);
$distance = ($res[routes][0][legs][0][distance][value]/1609.344).' miles';
$duration = $res[routes][0][legs][0][duration][text];
$pax = $_GET[pax];
if($pax==6||$pax==7||$pax==8){$rate=$small;}
if($pax==9||$pax==10||$pax==11){$rate=$med;}
if($pax==12||$pax==13||$pax==14||$pax==15||$pax==16){$rate=$large;}
foreach($dists as $ix => $val)
{
if($val>$distance)
{
break;
}else{
$price = $distance*$rate[$ix];
}
}
echo '<table align="center"><tr><td>Distance:</td><td><span id="q_distance">'.number_format($distance,2).' miles</span></td></tr>
<tr><td>Time:</td><td><span id="q_duration">'.$duration.'</span></td></tr>
<tr><td>Price:</td><td><span id="q_price">£'.number_format($price,2).'</span></td></tr>
<tr><td>Price Each:</td><td><span id="q_each">£'.number_format($price/$pax,2).'</span></td></tr>
</table>';
$price = number_format($price/$pax,2);
}
}
function get_html($url,$ref='')
{
$ch = curl_init();
if(DEBUG)
{
// echo 'Download: '.$url;
// fas();
}
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; //browsers keep this blank.
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows;U;Windows NT 5.0;en-US;rv:1.4) Gecko/20030624 Netscape/7.1 (ax)');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE);
$result = curl_exec ($ch);
curl_close ($ch);
return($result);
}
?>