当我为getdriving方向api制作网址时,我想在两个位置之间画两条路的行车路线
O(D*N*logK)
所以当我用谷歌搜索它时说使用urlencoder当我在我的网址中使用时错误没有被抛出但是我的json是空的这样
Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 133 but the url gives json
请告诉我哪里出错了
我的代码
error_message "Invalid request. Missing the 'origin' parameter."
routes
status "INVALID_REQUEST"
我的parsejson
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还有任何错误
答案 0 :(得分:0)
我认为您的uri编码存在问题。
对于方向uri,我使用了这段代码。它的工作正常。根据您的需要进行修改..
private String getDirectionsUrl(LatLng origin,LatLng dest){
// Origin of route
String str_origin = "origin="+origin.latitude+","+origin.longitude;
// Destination of route
String str_dest = "destination="+dest.latitude+","+dest.longitude;
// Sensor enabled
String sensor = "sensor=false";
// Building the parameters to the web service
String parameters = str_origin+"&"+str_dest+"&"+sensor;
// Output format
String output = "json";
return "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters;
}