Hi, I am very confused, please can someone direct me here.
I have a blank app with the below code. It works perfectly when I run it as a blank app.
I then copied it exactly to the “onRecord” in a Grid application, and when I run the Grid application it works perfectly.
Here is the confusion:.
I change the ‘from’ and ‘to’ values instead of being hard coded to a values as per table field values in the grid ( {startLocation} and {toLocation} respectfully). I get a series of errors. [TABLE=“class: scErrorTable, align: center, cellpadding: 0, cellspacing: 0”]
[TR]
[TD=“class: scErrorTitle, bgcolor: #FFDDDD, align: left”]Error[/TD]
[/TR]
[TR]
[TD=“class: scErrorMessage, bgcolor: #FFDDDD, align: center”]Undefined property: stdClass::$duration[/TD]
[/TR]
[/TABLE]
[TABLE=“class: scErrorTable, align: center, cellpadding: 0, cellspacing: 0”]
[TR]
[TD=“class: scErrorTitle, bgcolor: #FFDDDD, align: left”]Error[/TD]
[/TR]
[TR]
[TD=“class: scErrorMessage, bgcolor: #FFDDDD, align: center”]Trying to get property of non-object[/TD]
[/TR]
[/TABLE]
[TABLE=“class: scErrorTable, align: center, cellpadding: 0, cellspacing: 0”]
[TR]
[TD=“class: scErrorTitle, bgcolor: #FFDDDD, align: left”]Error[/TD]
[/TR]
[TR]
[TD=“class: scErrorMessage, bgcolor: #FFDDDD, align: center”]Undefined property: stdClass::$distance[/TD]
[/TR]
[/TABLE]
[TABLE=“class: scErrorTable, align: center, cellpadding: 0, cellspacing: 0”]
[TR]
[TD=“class: scErrorTitle, bgcolor: #FFDDDD, align: left”]Error[/TD]
[/TR]
[TR]
[TD=“class: scErrorMessage, bgcolor: #FFDDDD, align: center”]Trying to get property of non-object[/TD]
[/TR]
[/TABLE]
The exact code is:
$from = “22 Centre Rd, Morningside Sandton Gauteng South Africa”; // {startLocation}
$to = “123 Main Street, Johannesburg Gauteng South Africa”; // {toLocation}
$from = urlencode($from);
$to = urlencode($to);
$data = file_get_contents(“http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=en-EN&sensor=false”);
$data = json_decode($data);
$seconds = 0;
$distance = 0;
foreach($data->rows[0]->elements as $road) {
$seconds += $road->duration->value;
$distance += $road->distance->value;
}
$hours = floor($seconds / (60 * 60));
// extract minutes
$divisor_for_minutes = $seconds % (60 * 60);
$minutes = floor($divisor_for_minutes / 60);
// extract the remaining seconds
$divisor_for_seconds = $divisor_for_minutes % 60;
$seconds = ceil($divisor_for_seconds);
//create string HH:MM:SS
$ret = $hours.":".$minutes.":".$seconds;
{kms}=$distance*0.001; /// shows distance in km’s between {startLocation} and {toLocation}