My program uses google maps directions for web Services to find a route between two points. The result is parsed and stored in variable.
This variable is then used to co
I figured out how to solve it in java.I adapted user geocozip javascript code. In my case, as no waypoints are provided, I just need one leg. So my parse function got this:
List path = new ArrayList();
for(int j = 0; j< numSteps; ++j){
final JSONObject step = steps.getJSONObject(j);
final JSONObject polyline = step.getJSONObject("polyline");
final String polylinePoint = polyline.getString("points");
List coordinates = decodePath(polylinePoint);
for( int k = 0; k < coordinates.size(); ++k){
path.add(coordinates.get(k));
}
}
It is also necessary re-encode and then put in a format URL readable.
String newPath = path.createPolyLine(encodedPath);
String locationsContent="";
locationsContent = URLEncoder.encode(newPath, "UTF-8")
.replaceAll("\\%40", "@")
.replaceAll("\\+", "%20")
.replaceAll("\\%21", "!")
.replaceAll("\\%27", "'")
.replaceAll("\\%28", "(")
.replaceAll("\\%29", ")");