title: Google direction API returns REQUEST_DENIED when called from Android
body: <p>I have this code using which I am trying to call the Google directions API webservices from my Android device: (4.1 HTC 1X). However I get the response REQUEST_DENIED. Why?</p>
  
  <p>Here's my code - nothing fancy here:</p>
  
  <pre><code>String hosturl="https://maps.googleapis.com/maps/api/directions/xml?";
  String url = "origin=" +lat1 + "," + lon1  + "&amp;destination=" + lat2 + "," + lon2 + "&amp;sensor=true";
  String tag[] = { "lat", "lng" };
  
  ArrayList&lt;GeoPoint&gt; list_of_geopoints = new ArrayList&lt;GeoPoint&gt;();
  HttpResponse response = null;
  try {
      HttpClient httpClient = new DefaultHttpClient();
      HttpContext localContext = new BasicHttpContext();
      String newurl = URLEncoder.encode(url, "UTF-8");
      String finalurl = hosturl + newurl;
      System.out.println(" Direction request going out:"+ finalurl);
      HttpPost httpPost = new HttpPost(finalurl);
      try {
          response = httpClient.execute(httpPost, localContext);
      }
      catch (Exception exc) {
          System.out.println("IO Exeception in making direction request: "+ exc.getMessage());
          //list_of_geopoints=null;
          return list_of_geopoints;
      }
      InputStream in = response.getEntity().getContent();
      DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      Document doc = builder.parse(in);
      if (doc != null) {
          NodeList nl1, nl2, statusList;
          statusList = doc.getElementsByTagName("status");
  </code></pre>
  
  <p>When I print the status node, I get a REQUEST_DENIED. </p>
  
  <p>I see that others have also posted the same but did not get any response. </p>
  
  <p>I already have a key for my MAP API. However, I am not using the latest Google Places API as I believe I do not need to. I am completely clueless. I am making the app using Android 3.2 while running it on my HTC 1x which uses 4.1.</p>
  
  <p>The same works well when used from the browser. For example, the following when invoked from any browser would work ( but not from my android code):
  <a href="http://maps.googleapis.com/maps/api/directions/xml?origin=37.2345487,-121.5840723&amp;destination=37.236064,-121.961595&amp;sensor=false" rel="nofollow">http://maps.googleapis.com/maps/api/directions/xml?origin=37.2345487,-121.5840723&amp;destination=37.236064,-121.961595&amp;sensor=false</a></p>
  
  <p>I may be doing something very stupid but cannot catch it.</p>