このコードを使用して、Android デバイスから Google 方向 API Web サービスを呼び出そうとしています: (4.1 HTC 1X)。ただし、REQUEST_DENIED という応答が返されます。なんで?
ここに私のコードがあります - ここには空想はありません:
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");
ステータス ノードを出力すると、REQUEST_DENIED が返されます。
他の人も同じことを投稿しているようですが、何の反応も得られませんでした。
MAP API のキーを既に持っています。ただし、最新の Google Places API は使用する必要がないと考えているため、使用していません。私は完全に無知です。4.1 を使用する HTC 1x で実行しながら、Android 3.2 を使用してアプリを作成しています。
ブラウザから使用する場合も同様です。たとえば、任意のブラウザーから呼び出された場合、次のように動作します (ただし、私の Android コードからではありません): http://maps.googleapis.com/maps/api/directions/xml?origin=37.2345487,-121.5840723&destination=37.236064,- 121.961595&センサー=false
私は非常に愚かなことをしているかもしれませんが、それを捕まえることはできません。