Hallo,
Ik ben bezig voor een website waar een berekening moet worden gemaakt van de kilometerkosten. Men vult postcode of adres+plaatsnaam in en de kilometerkosten worden berekend. Alleen nu komt het, het script dat ik gebruik wil maar niet afronden op 2 decimalen! Ik heb van alles geprobeerd met Math rounds etc. Geen effect, of het script werkt helemaal niet meer. Ik dank jullie alvast hartelijk voor jullie hulp! Hierbij het script:
Het script maakt gebruik van de Google Maps database.Code:<!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> <title>Connectcase.nl: Gratis afstand berekening tussen twee plaatsen met Google Maps</title> <meta http-equiv="content-Type" content="text/html; charset=iso-8859-1" /> <meta name="description" content="Gratis afstand berekening tussen twee plaatsen met Google Maps ipv. postcode tabel"> <meta name="keywords" content="afstand, berekening, kosten, twee, plaatsen, google maps, postcode, tabel, distance, calculation"> <meta name="abstract" content="Gratis afstand berekening tussen twee plaatsen met Google Maps ipv. postcode tabel"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="verify-v1" content="K8eGACCrm4Azib1o2Tk+4UQ9UJX1jk5WtQzsx4f8hVQ=" /> <meta name="y_key" content="b0c2a0e275c4c2b0" /> <meta name="revisit-after" content="7 Days" /> <meta name="ratings" content="general" /> <meta name="copyright" content="Connectcase © 2008"> <meta name="robots" content="all"> <meta name="language" content="nl"> <meta name="author" content="Connectcase.nl"> <meta name="copyright" content="Connectcase"> <meta http-equiv="Window-target" content="_top"> <script src="http://maps.google.nl/maps?file=api&v=2&key=ABQIAAAAEOe-MThhhCIOMKwWDPbwhRRS8CkXXPt5sVVf4YkaT1EeWYX3cBRwsjSrpuJm-goUrjhfsUYusXdklQ" type="text/javascript"></script> <script type="text/javascript"> function initialize() { if (GBrowserIsCompatible()) { // nieuw object ZONDER parameters, want we willen nl. geen geschreven route EN geen map tonen.... // http://code.google.com/apis/maps/documentation/reference.html#GDirections gdir = new GDirections(); GEvent.addListener(gdir,"load", set_distance); } } function setDirections(fromAddress, toAddress, locale) { // http://code.google.com/apis/maps/documentation/reference.html#GDirectionsOptions gdir.load("from: " + fromAddress + " to: " + toAddress, {locale: locale, travelMode:G_TRAVEL_MODE_DRIVING,avoidHighways: false} ); } function set_distance() { // extra: foutafhandeling, kan handig zijn!!! handleErrors(); document.getElementById("afstand").innerHTML = gdir.getDistance().meters * 2 * 19 / 100 / 1000; afstand = afstand * 100; afstand = Math.round(afstand); afstand = afstand / 100; } function handleErrors() { // http://code.google.com/apis/maps/documentation/reference.html#GGeoStatusCode 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 || gdir.getStatus().code == G_GEO_MISSING_ADDRESS) 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_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 if (gdir.getStatus().code == G_GEO_UNAVAILABLE_ADDRESS) 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_UNKNOWN_DIRECTIONS) alert("The GDirections object could not compute directions between the points mentioned in the query. This is usually because there is no route available between the two points, or because we do not have data for routing in that region.\n Error code: " + gdir.getStatus().code); else if (gdir.getStatus().code == G_GEO_TOO_MANY_QUERIES) alert("The given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of time.\n Error code: " + gdir.getStatus().code); } </script> </head> <body onload="initialize()" onunload="GUnload()"> <form action="#" onsubmit="setDirections(this.from.value, this.to.value, 'nl'); return false"> <table border="0"> <tr> <td> </td><td><input type="hidden" size="1" id="fromAddress" name="from" value="7327LB"/></td> <td>postcode te keuren auto: </td><td><input type="text" size="40" id="toAddress" name="to" /></td> <td><input tabindex="1" name="submit" type="submit" value="Bereken reiskosten!" /></td> </tr> </table> </form> <td>€</td> <div id= "afstand"></div> </body> </html>
PAS OP! Mensen die dit script willen gebruiken, geen probleem. Alleen wel even je eigen 'Google-code' erin plakken A.U.B.
Uit eindelijk moet de uitkomst dus afgerond worden op 2 decimalen (€32,45 ipv €32,453493)
Alvast heel erg bedankt!
- Hulp met berekeningsscript nodig!
-
16-03-2009, 16:22 #1
- Berichten
- 128
- Lid sinds
- 16 Jaar
Hulp met berekeningsscript nodig!
-
In de schijnwerper
Gezocht: Linkopties Installatie / Duurzaamheid / Groen / Energie / WonenOverige dealsAutoriteit links aangeboden | Hoge DR & DA + Duizenden bezoekers. Alle NICHES vrijwelOverige dealsAllesOverFreelancen.nl - DA11 - Uit 2006Domein te koop(Premium) Hoge DA Backlink | DR 95 | RD 4,2 MiljoenAdvertentieruimte -
16-03-2009, 17:00 #2
- Berichten
- 209
- Lid sinds
- 18 Jaar
Math.round(value); moet 100% werken. Misschien wel voor de zekerheid even parseInt over value heen halen, misschien dat dat het probleem is.
-
16-03-2009, 17:11 #3
- Berichten
- 128
- Lid sinds
- 16 Jaar
Zou iemand dat voor mij in het script willen zetten, testen en posten? (Kan gewoon local) want ik heb het al 1000x geprobeerd met Math.round en geen resultaat.
Alvast bedankt
-
16-03-2009, 17:27 #4
De Leeuw Internet Marketing
- Berichten
- 141
- Lid sinds
- 17 Jaar
Dit klopt niet:
Code:handleErrors(); document.getElementById("afstand").innerHTML = gdir.getDistance().meters * 2 * 19 / 100 / 1000; afstand = afstand * 100; afstand = Math.round(afstand); afstand = afstand / 100;
Code:afstand = gdir.getDistance().meters * 2 * 19 / 100 / 1000; afstand = afstand * 100; afstand = Math.round(afstand); afstand = afstand / 100; //gratis bonus: van punt naar komma: afstand = afstand.toString(); afstand = afstand.replace(/\./, ','); //einde gratis bonus document.getElementById("afstand").innerHTML = afstand;
Laatst aangepast door Daniël de L. : 16-03-2009 om 17:32
-
17-03-2009, 15:21 #5
- Berichten
- 128
- Lid sinds
- 16 Jaar
Heel erg bedankt! Alleen volgens mij werkt het nu niet meer in IE7?? :(
Wel in FireFox en MineField (64-Bit FF)
Tags voor dit bericht
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic