javacharacterillegal-characters

Illegal character at query



I have an application that needs to query Google for directions etc. I have reorganised my code recently, made some optimalisation to query for route with waypoints to cut on request send count. Now there is a problem: I'm getting
java.lang.IllegalArgumentException: Illegal character in query at index 146: http://maps.googleapis.com/maps/api/directions/json?origin=52.4000826,16.8928842&destination=52.4129715,16.8296386&waypoints=52.4053469,16.8969666|52.4049754,16.8811389&sensor=false

I believe that char at index 146 is '|'. What is wrong with that character?

Thanks for any advice.

This is my code for building query:

try {
            String requestString = "http://maps.googleapis.com/maps/api/directions/"
                    + "json?origin="
                    + Double.toString(start.getLatitude())
                    + ","
                    + Double.toString(start.getLongitude())
                    + "&destination="
                    + Double.toString(end.getLatitude())
                    + "," + Double.toString(end.getLongitude());

            if (points.length > 2) {
                String waypoints = "&waypoints="
                        + Double.toString(points[1].getLatitude()) + ","
                        + Double.toString(points[1].getLongitude());
                for (int i = 2; i < points.length - 1; i++) {
                    waypoints = waypoints + "|"
                            + Double.toString(points[i].getLatitude())
                            + ","
                            + Double.toString(points[i].getLongitude());
                }
                requestString = requestString + waypoints;
            }
            requestString = requestString + "&sensor=false";

Solution

  • UFL1138 is right. Replacing "|" with "%7C" worked. Thanks