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?
Here's my code - nothing fancy here:
String hosturl="https://maps.googleapis.com/maps/api/directions/xml?";
String url = "origin=" +lat1 + "," + lon1 + "&destination=" + lat2 + "," + lon2 + "&sensor=true";
String tag[] = { "lat", "lng" };
ArrayList<GeoPoint> list_of_geopoints = new ArrayList<GeoPoint>();
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");
When I print the status node, I get a REQUEST_DENIED.
I see that others have also posted the same but did not get any response.
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.
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): http://maps.googleapis.com/maps/api/directions/xml?origin=37.2345487,-121.5840723&destination=37.236064,-121.961595&sensor=false
I may be doing something very stupid but cannot catch it.