我在Android中使用Google API V2。如果我想获得从pointA到pointB的路由,但我想通过pointC和pointD,Google says来表示请求应该是:
http://maps.googleapis.com/maps/api/directions/json?origin=pointA&destination=pointB&waypoints=pointC|pointD
然而,我收到此错误:
Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 191: blablabla (it is because | character)
at java.net.URI.create(URI.java:727)
at org.apache.http.client.methods.HttpPost.<init>(HttpPost.java:79)
at mcd0n3ld.roadcheckpoints.ToolsMap$JSONParser.getJSONFromUrl(ToolsMap.java:216)
[some more but not interesting...]
有关如何解决此问题的任何想法?
亲切的问候, 劳尔
答案 0 :(得分:4)
您需要使用URL Encoder
对参数进行编码String params = "pointC|pointD";
try {
params = URLEncoder.encode(params, "UTF-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
然后concat
String url = "http://maps.googleapis.com/maps/api/directions/json?origin=pointA&destination=pointB&waypoints="+params;