title: diffrence between distance matrix api and direction api
body: <p>i want to display route on google map, i know for that direction api is used. further more i want time duration and distance between two points, that is also we can get from direction api. but next step is to calculate location distance and time duration as one person from point A is moving towards point B continuously, then i only want time duration and distance. so the question is...</p>
  
  <p>1) for getting continuous duration and distance without route information which api to be used? distance matrix or direction api? what is difference between them? i'm using direction api now. should i use distance matrix api?</p>
  
  <p>2) i'm using diraction api without passing key...<a href="https://maps.googleapis.com/maps/api/directions/json?origin=23.0509738,72.5193273&amp;destination=23.046219,72.515696&amp;sensor=false&amp;units=metric&amp;mode=driving" rel="nofollow noreferrer">https://maps.googleapis.com/maps/api/directions/json?origin=23.0509738,72.5193273&amp;destination=23.046219,72.515696&amp;sensor=false&amp;units=metric&amp;mode=driving</a> it is giving me same result as you can see in example. so do i use it without passing key? or i have to pass the key along with url?</p>
  
  <pre><code>public String getDistance(final double lat1, final double lon1, final double lat2, final double lon2){
      String parsedDistance;
      String response;
  
      Thread thread=new Thread(new Runnable() {
        @Override
        public void run() {
          try {
            URL url = new URL("http://maps.googleapis.com/maps/api/directions/json?origin=" + lat1 + "," + lon1 + "&amp;destination=" + lat2 + "," + lon2 + "&amp;sensor=false&amp;units=metric&amp;mode=driving");
            final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            InputStream in = new BufferedInputStream(conn.getInputStream());
            response = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
  
            JSONObject jsonObject = new JSONObject(response);
            JSONArray array = jsonObject.getJSONArray("routes");
            JSONObject routes = array.getJSONObject(0);
            JSONArray legs = routes.getJSONArray("legs");
            JSONObject steps = legs.getJSONObject(0);
            JSONObject distance = steps.getJSONObject("distance");
            parsedDistance=distance.getString("text");
          } catch (ProtocolException e) {
            e.printStackTrace();
          } catch (MalformedURLException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          } catch (JSONException e) {
            e.printStackTrace();
          }
        }
      });
  
      thread.start();
  
      try {
        thread.join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
  
      return parsedDistance;
  }
  </code></pre>