Source: view [edit]
Function name: distance
Arguments: fromAddr,toAddr
Description: Calculates the distance in miles fromAddr toAddr
Page type: webl
Render function:   distanceRender
Module: global

Page source:

// Calculates distance using Google's distance calculatora
//     URL[Google Documentation|http://code.google.com/apis/maps/documentation/distancematrix]

var P = GetURL(`https://maps.googleapis.com/maps/api/distancematrix/xml`,
   [. "origins"=fromAddr, "destinations"=toAddr, "sensor"="false", "units"="imperial"
    .]);

var Distance = Pat(P, `(\d+) mi`) inside Elem(P, "distance");
var Duration = Elem(P, "text") inside Elem(P, "duration");

var distMi = ToInt(Distance[0][1]) ? 0;
var dur = Str_Trim(Text(Duration[0])) ? "?";

[. distanceInMiles = distMi, duration=dur .];


  


/* Google call returns structure:

<?xml version="1.0" encoding="UTF-8"?>
<DistanceMatrixResponse>
 <status>OK</status>
 <origin_address>Oakland, CA, USA</origin_address>
 <destination_address>Los Angeles, CA, USA</destination_address>
 <row>
  <element>
   <status>OK</status>
   <duration>
    <value>22434</value>
    <text>6 hours 14 mins</text>
   </duration>
   <distance>
    <value>599440</value>
    <text>372 mi</text>
   </distance>
  </element>
 </row>
</DistanceMatrixResponse>

*/