On Sep 10, 12:18 pm, JohnPru <[EMAIL PROTECTED]> wrote:
> I have tried as you suggested but am not sure if I understand
> correctly.
> looking at the result of using (dirn.getDistance().meters) I am still
> getting the html as well as the distance!
That should return just a number.
> also i am a bit confused as I have used
> GDownloadUrl("callback_miles.php?distance="+ dist,callbackFunction);
> On the callback_miles.php page I have just used "$val =
> $_GET['distance'];
> echo "the distance is: $val";
> I am a bit lost, do I need to wtite a call back function ?
Yes. The documentation for GDownloadUrl indicates that it requires a
callback function which accepts the data returned. Your callback
function could do something with that, or could just discard it.
callback_miles.php should accept a parameter called "distance" -- you
appear to have done that -- with the intention that it should be used
to calculate a cost. So the result your script echoes should be the
cost. The callback function should accept that data and put it into
the page.
Within callback_miles.php,
$val=$_GET['distance']
echo $val * 1609 * 14.5 // calculate cost at GBP14.5 per mile
Within your callback function,
function callbackFunction(data) {
document.getElementById("costGoesHere").innerHTML=data;
}
You may be able to get away without using GDownloadUrl, and
calculating the cost within your page, simply using the distance which
is already available in Javascript. If you need to include other
parameters, like vehicle size, or you want to keep your calculation
secret, you will need to move it server-side.
Andrew
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" 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
-~----------~----~----~----~------~----~------~--~---