On Jan 23, 9:52 am, onlydesigning <[email protected]> wrote: > I need urgent help on fixing this code
Urgent? I don't think so. > since I know very > little about java and Google API coding. No worries. The API has nothing to do with Java. :-) -- Marcelo - http://maps.forum.nu -- Here is the code and the site > is at yestaxicab.com - the calc is linked under the rates page. > > <script src="http://maps.google.com/maps? > file=api&v=2&key=ABQIAAAA1Zjp1-x1kq9THzhEJ7Ft9RSGZLnhTX2D372G- > BYKDzEty2BaZBTSLVIJDouoTRLsUeP2U7QovZ5o7g" > type="text/javascript"> > > function calculatefare() > > { > > var geocoder, location1, location2, gDir; > > function initialize() { > geocoder = new GClientGeocoder(); > gDir = new GDirections(); > GEvent.addListener( > gDir, "load", function() { > var resultTable; > var drivingDistanceMiles = > parseInt(gDir.getDistance().meters / 160.9344)/10; > var drivingTaximeter = (drivingDistanceMiles * 2.5) + 2; > > resultTable = '<table border="0" cellpadding="2" > cellspacing="0" align="center">'; > resultTable += ' > <tr><td colspan="2" style="border-left:1px solid #FFFF99;border-top: > 1px solid #FFFF99;border-right:1px solid #FFFF99;font-family: New > Times Roman; font-size: 12pt;">Origin / Pick-up: '; > resultTable += location1.address; > resultTable += '</td></tr> > <tr><td align="center" style="border-left:1px solid #FFFF99;border-top: > 1px solid #FFFF99;border-right:1px solid #FFFF99;border-bottom:1px > solid #FFFF99;font-family: New Times Roman; font-size: > 12pt;">Latitude: '; > resultTable += location1.lat; > resultTable += '</td><td align="center" style="border-top: > 1px solid #FFFF99;border-right:1px solid #FFFF99;border-bottom:1px > solid #FFFF99;font-family: New Times Roman; font-size: > 12pt;">Longitude: '; > resultTable += location1.lon; > resultTable += '</span></td></tr> > '; > resultTable += ' > <tr><td colspan="2"> </td></tr> > '; > resultTable += ' > <tr><td colspan="2" style="border-left:1px solid #FFFF99;border-top: > 1px solid #FFFF99;border-right:1px solid #FFFF99;font-family: New > Times Roman; font-size: 12pt;">Destination / Drop-off: '; > resultTable += location2.address; > resultTable += '</td></tr> > <tr><td align="center" style="border-left:1px solid #FFFF99;border-top: > 1px solid #FFFF99;border-right:1px solid #FFFF99;border-bottom:1px > solid #FFFF99;font-family: New Times Roman; font-size: > 12pt;">Latitude: '; > resultTable += location2.lat; > resultTable += '</td><td align="center" style="border-top: > 1px solid #FFFF99;border-right:1px solid #FFFF99;border-bottom:1px > solid #FFFF99;font-family: New Times Roman; font-size: > 12pt;">Longitude: '; > resultTable += location2.lon; > resultTable += '</span></td></tr> > </table> > <br><span style="font-family: New Times Roman; font-size: > 12pt;">Approximately:</span><br>'; > resultTable += '<div align="center" style="font-family: > New Times Roman; font-size: 18pt; font-weight: bold;"> > > Taximeter Fare: '; > resultTable += drivingTaximeter + '</div> > '; > resultTable += '<div align="center" style="font-family: > New Times Roman; font-size: 18pt; font-weight: bold;"> > > Miles Travelled: '; > resultTable += drivingDistanceMiles + ' miles</div> > '; > > document.getElementById('results').innerHTML = > resultTable; > > // document.getElementById('results').innerHTML = > '<strong>Origin / Pick-up: </strong>' + location1.address + > ' (<strong>Latitude: </strong>' + location1.lat + ' / > <strong>Longitude: </strong>' + location1.lon + ')<br /><strong>Destination / > Drop-off: </strong>' + location2.address + > > ' (<strong>Latitude: </strong>' + location2.lat + ' / > <strong>Longitude: </strong>' + location2.lon + ')<br /><strong>Taximeter > Fare: $</strong>' + drivingTaximeterLow + ' to $' + > > drivingTaximeterHigh + '<br /><strong>Driving Distance: </strong>' + > drivingDistanceMiles + ' miles (or ' + 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 find 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 find 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); > } > } > ); > } > } > ); > } > > //<iframe width="425" height="350" frameborder="0" scrolling="no" > marginheight="0" marginwidth="0" src="http://maps.google.com/maps? > f=d&source=s_d&saddr=BWI+Airport&daddr=8503+Church+Ln., > +Randallstown,+MD+21133&hl=en&geocode=FanVVQIdTSBu- > ykL4MK7_OK3iTFAF5f6DBUAAA%3BFT2pWAIdK4ls- > ykf0t6JthnIiTHkpRKTDN0k7w&mra=prev&sll=39.179689,-76.668851&ssp > n=0.055755,0.109348&g=BWI > +Airport&ie=UTF8&ll=39.272425,-76.720835&spn=0.18563,0.10561&am > p;output=embed"></ > iframe><br /><small><a href="http://maps.google.com/maps? > f=d&source=embed&saddr=BWI+Airport&daddr=8503+Church+Ln., > +Randallstown,+MD+21133&hl=en&geocode=FanVVQIdTSBu- > ykL4MK7_OK3iTFAF5f6DBUAAA%3BFT2pWAIdK4ls- > ykf0t6JthnIiTHkpRKTDN0k7w&mra=prev&sll=39.179689,-76.668851&ssp > n=0.055755,0.109348&g=BWI > +Airport&ie=UTF8&ll=39.272425,-76.720835&spn=0.18563,0.10561" > style="color:#0000FF;text-align:left">View Larger Map</a></small> > > </script> > > <br /> > <table align="center" border="0" cellpadding="0" cellspacing="0" > id="pagetable"> > <tbody> > <tr> > > <form action="#" onsubmit="showLocation(); return false;"> > </form> > </tr> > </tbody></table> > <table align="center" border="0" cellpadding="0" cellspacing="2"> > <tbody> > <tr> > <td align="center" colspan="2" style="font-family: New Times > Roman; font-size: 12pt;">Use the following form to calculate you cab > fare between two places.<br /> > Please note this form is only as accurate as the distances supplied by > Google.</td> > </tr> > <tr> > <td align="right" style="font-family: New Times Roman; font- > size: 12pt; font-weight: bold;">Origin / Pick-up: </td> > <td><input name="address1" size="40" type="text" value="" /></td> > > </tr> > <tr> > <td align="right" style="font-family: New Times Roman; font- > size: 12pt; font-weight: bold;">Destination / Drop-off: </td> > <td><input name="address2" size="40" type="text" value="" /></td> > > </tr> > <tr> > > <td><a href="http://maps.google.com/"><img border="0" > src="http://www.secform4.com/images/powered_by_google.gif" /></a></td> > <td align="right"><input type="submit" value="Calculate" /></ > td> > </tr> > </tbody></table> > <br /> > <div id="results"> > </div> > > THANK YOU! -- You received this message because you are subscribed to the Google Groups "Google Maps API V2" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.
