0
私は方向APIをgetdrivingのURLを作るときに、2つのウェイポイントを持つ2つの場所間の走行経路を描画するには、このmy gerdirection api urlようjava.lang.IllegalArgumentExceptionが:インデックス133で、クエリ内の不正な文字:
Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 133 but the url gives json
を語ります私はGoogleで検索するとき
は、だから、私は私のURLでエラーがスローされていないことを使用する場合のURLEncoderに使用すると述べたが、私のJSONは、この
error_message "Invalid request. Missing the 'origin' parameter."
routes
status "INVALID_REQUEST"
のような空であります私は私のコード
public String getMapsApiDirectionsUrl() {
final LatLng source = new LatLng(dsla, dslo);
final LatLng path1 = new LatLng(dp1la, dp2lo);
final LatLng path2=new LatLng(dp2la,dp2lo);
final LatLng dest = new LatLng(ddla, ddlo);
String origin = "origin=" + source.latitude + "," + source.longitude;
String waypoints = "waypoints=optimize:true"+"|"+ path1.latitude + ","+ path1.longitude +"|"+ path2.latitude +","+ path2.longitude ;
String destination = "destination=" + dest.latitude + "," + dest.longitude;
String way="",sour="",desty="";
try {
way = URLEncoder.encode(waypoints, "UTF-8");
desty = URLEncoder.encode(destination, "UTF-8");
sour = URLEncoder.encode(origin, "UTF-8");
}catch (UnsupportedEncodingException e) {
}
String key = "AIzaSyDOidVs6_dHl0cjEJ0-OhMfUY0oNFf1SOE ";
String params = origin+ "&" + destination+ "&" + waypoints +"&"+key;
String output = "json";
// String url1="https://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&key=YOUR_API_KEY";
String url = "https://maps.googleapis.com/maps/api/directions/"
+output + "?" +params;
Log.d("taqg",url);
return url;
}
私parsejson
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
String results="";
// constructor
public String getJSONFromUrl(final String url) {
class GetDataJSON extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
json = sb.toString();
is.close();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
return json;
}
@Override
protected void onPostExecute(String result) {
results=json;
Log.d("tag",results);
}
}
GetDataJSON g = new GetDataJSON();
g.execute();
return results;
}
}
私はあなたに問題があると思い
私はウェイポイントを使用していますが、このURLはウェイポイントをサポートしません –