0

我必须打一个urlhttp://maps.googleapis.com/maps/api/distancematrix/json?origins=0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0| 0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0, 0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0&destinations=19.0,72.0&mode=driving&sensor=false

我收到以下错误:

11-14 14:14:21.154: E/AndroidRuntime(2813): Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 71: http://maps.googleapis.com/maps/api/distancematrix/json?origins=0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0&destinations=19.0,72.0&mode=driving&sensor=false

我也尝试过URLencodedUtils.format(),但我遇到了同样的错误。

解决方案?

4

1 回答 1

4

尝试

String query = URLEncoder.encode("origins=0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0|0.0,0.0&destinations=19.0,72.0&mode=driving&sensor=false", "utf-8");
String url = "http://maps.googleapis.com/maps/api/distancematrix/json?" + query;
于 2013-11-14T08:49:03.613 回答