title: GET from JavaScript, problems parsing XML? Or Maps API errors?
body: <p>I'm trying to make an HTTP get from Javascript, calling Google Maps to get transit duration from A to B, and then parsing the resulting XML as follows:</p>
  
  <pre><code>function getTransitTime(match) {
      var homeBase = '&lt;Address 1&gt;';
      var distURL = 'https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&amp;key=API_KEY_I_GOT&amp;mode=transit&amp;arrival_time=1519977600&amp;origins=' + homeBase + '&amp;destinations=' + match;
  
      parser = new DOMParser();
      xmlDoc = parser.parseFromString(httpGet( distURL ), "text/xml");
      var finRet = $(xmlDoc).find('duration').text()
      return finRet;
  }
  
  function httpGet(theUrl)
  {
      var xmlHttp = new XMLHttpRequest();
      xmlHttp.open( "GET", theUrl, true );
      xmlHttp.send( null );
      return xmlHttp.responseText;
  }
  </code></pre>
  
  <p>I receive both the NoApiKeys and SensorNotRequired errors in the js console. What am I doing wrong?</p>
  
  <p>There are probably even more problems with this:</p>
  
  <ul>
  <li><p>I'm not sure how to deal with spaces in address 1 (and even worse, "match").</p></li>
  <li><p>Duration has two sub-fields (one being text), not sure if parsing is correct. Note that my query works correctly in the browser (with the same API key) and the output XML is pasted below:</p></li>
  </ul>
  
  <pre class="lang-html prettyprint-override"><code>&lt;DistanceMatrixResponse&gt;
      &lt;status&gt;OK&lt;/status&gt;
      &lt;origin_address&gt;New York, NY, USA&lt;/origin_address&gt;
      &lt;destination_address&gt;Philadelphia, PA, USA&lt;/destination_address&gt;
      &lt;row&gt;
          &lt;element&gt;
              &lt;status&gt;OK&lt;/status&gt;
              &lt;duration&gt;
                  &lt;value&gt;5100&lt;/value&gt;
                  &lt;text&gt;1 hour 25 mins&lt;/text&gt;
              &lt;/duration&gt;
              &lt;distance&gt;
                  &lt;value&gt;145447&lt;/value&gt;
                  &lt;text&gt;145 km&lt;/text&gt;
              &lt;/distance&gt;
          &lt;/element&gt;
      &lt;/row&gt;
  &lt;/DistanceMatrixResponse&gt;
  </code></pre>
  
  
  
  <p>Any help? I wandered off trying to make something "simple" work, but ended up in the deep end :|</p>