Google距離行列APIを呼び出そうとしていますが、115で不正なクエリとしてエラーが発生します.これが私のコードです:
protected Document doInBackground(LatLng... latlng) {
String destinationURL = "";
// ASSUMING THAT FIRST LATLNG PASSED IS ALWAYS A SOURCE LOCATION
for(int index = 1; index < latlng.length; index ++)
{
destinationURL += latlng[index].latitude +"," + latlng[index].longitude;
if(index+1 != latlng.length)
{
destinationURL+= "|";
}
}
String url = "http://maps.googleapis.com/maps/api/distancematrix/xml?"
+ "origins=" + latlng[0].latitude + "," + latlng[0].longitude
+ "&destinations=" + destinationURL
+ "&sensor=false&mode=walking";
上記の URL を貼り付けると、結果は次のようになります:クエリの URL リンク
エラーの詳細:java.lang.IllegalArgumentException: Illegal character in query at index 115: http://maps.googleapis.com/maps/api/distancematrix/xml?origins=35.777418,-78.677666&destinations=35.78036,-78.67816|35.787515,-78.670456&sensor=false&mode=walking
上記の URL を呼び出すコード:
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpClient.execute(httpPost, localContext);
InputStream in = response.getEntity().getContent();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in);
return doc;
どんな助けでも大歓迎です。