How do i simplify this google maps distance calculator

So i put together this distance and rate calculator using google maps api, but since im not that great with javascript just yet, its all kind of pasted together, although it works just fine… im sure theres a better way to do this… heres the demo
http://tinyurl.com/bsvu5jn
(works in san diego only)

and heres the distance/rate calculator code

var geocoder, location1, location2, gDir;

function initialize() {
geocoder = new GClientGeocoder();
gDir = new GDirections();
var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
var drivingDistanceMiles = Math.round(drivingDistanceMiles*100)/100;

var drivingrate1 = Math.round((drivingDistanceMiles*3.00)+2.80);
var drivingrate2 = Math.round(((drivingDistanceMiles*3.00)+2.80)*1.15);
document.getElementById('results').innerHTML = '<strong>Driving Distance: </strong>' + drivingDistanceMiles + ' miles <br/><strong>Rate estimate: </strong> \$' + drivingrate1 + ' to \$' + drivingrate2+'<br/>';
document.getElementById('map').innerHTML = '<iframe src="distancemap.php?from='+ location1.address+'&to='+ location2.address+'" width="500" border="0" height="250" style="border:0px solid #fff; overflow:hidden">Browser not compatible. </iframe>';
document.getElementById('address').innerHTML = '<input type="text"style="display:none" name="pickup" value="'+ location1.address+'"><input type="text" name="dropoff" style="display:none" value=" '+ location2.address+'"/><input type="submit" value="submit"  class="submit" />';
});
}

function showLocation() {
if (!response || response.Status.code != 200)
{
}
else
{
if (!response || response.Status.code != 200)
{
}
else
{
}
});
}
});
}

the reason i use iframes is to load another map that shows the route between the starting address and the ending address, heres the code

var map;
var gdir;

function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
gdir = new GDirections(map, document.getElementById("directions"));

setDirections("<?php echo \$_REQUEST['from']; ?> san diego", "<?php echo \$_REQUEST['to']; ?> san diego");

}
}

}

id like to learn how to just merge the two codes, anyone know how to do this?

thanks!

building a similar rate fare estimator app as well - did u ever fig it out?

Hi there,

Welcome to the forums

Maybe the OP will return and give you an answer, but as the thread is 8 years old, I doubt it.
I would therefore suggest starting a new thread, stating your problem and providing the coe you have so far.
That way, you’ll be much more likely to get an answer.