Jump to content

Google Free Taxi Script


npsari

Recommended Posts

Hello,

 

This script is provided by Google maps. It uses the mileage between one place to another to another, then multiplies it by the price per mile, to give the Price of the journey.

The problem is, we charge 3 different prices: Normal Taxi, MPV and Van

 

<script src=" http://maps.google.com/?file=api&v=2.x&key=ABQIAAAAdvr5JYYnjJ7QwkL0rI8FrxRfZHv9OEd3Hnby8E72WEHGAekdchQJINHRmw2K9eqQkSsnVCfbH6xLYw"
      type="text/javascript"></script>

<script src="http://www.deltacarstaxi.com/taxiscript/taxiquote.js"></script>

<body bgcolor="ADCCE9" onload="initialize()" onunload="GUnload()">

<form action='#' onsubmit='setDirections(this.from.value, this.to.value, this.locale.value); return false'>
<input type='hidden' id='locale' name='locale'>
<input type='hidden' id='fromAddress' name='from' value='RH1 1BB'>
<input type='hidden' id='toAddress' name='to' value='RH1 1BB'>
</form>
Price (Normal car) is: £<span id='costs1'> </span> 

</body> 

 

 

So, at the moment, the result comes out like this:

Price (Normal car) is: £20

 

But I want 3 results like this:

Price (Normal car) is: £20

Price (MPV) is: £30

Price (Van) is: £40

 

Basically, the MPV is x1.5 the price

And the VAN is x2 the price

 

Please tell me how to change the script. Your help is needed. Thank you much.

 

Ohh, by the way, this is part of the script too:

 

    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

    function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
// change these values to your own base start and finish values. There must be values here to work.
        setDirections("Gatwick airport UK", "Crawley", "en_US");
      }
    }
    
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

    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.");
   
}
// the quote mechanism. change the miles*2.90 etc to your own mileage rates. This example has 3 zones under 150 miles, 150 - 250 miles and over 250 miles. You can add as many zones as you like by replicating the else if functions and setting you own bands. The 70.00 in the final band is the minimum price and you can change this to what ever minimum charge you have.
function onGDirectionsLoad(){ 
var miles = gdir.getDistance().meters*0.000621371192237334;


document.getElementById("costs1").innerHTML =  

(Math.round((miles*1.3+3)).toFixed(2))   ; 


}

Link to comment
Share on other sites

You will have to make two changes. The price and where it is written is done in the 'function onGDirectionsLoad()'  I have added two more lines and please note I made a change in the multiplier for the rate.

function onGDirectionsLoad(){ 
var miles = gdir.getDistance().meters*0.000621371192237334;
document.getElementById("costs1").innerHTML =  
document.getElementById("costs1").innerHTML = (Math.round((miles*1.3+3)).toFixed(2));
document.getElementById("costs2").innerHTML = (Math.round((miles*1.9+3)).toFixed(2));
document.getElementById("costs3").innerHTML = (Math.round((miles*2.3+3)).toFixed(2));
}

 

And the second it to give 2 new places where the info is printed:

<!--//Price (Normal car) is: £<span id='costs1'> </span><br />-->
Price (Normal Taxi) is: £<span id='costs1'> </span><br />
Price (MPV) is: £<span id='costs2'> </span><br />
Price (Van) is: £<span id='costs3'> </span><br /><br />

 

Notice here that the 'costs1' has been changed.

 

You must change the multiplier to get correct results.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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