google maps static map polyline passing through lakes, river, mountains

后端 未结 2 1893
小鲜肉
小鲜肉 2020-12-12 07:32

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

2条回答
  •  时光说笑
    2020-12-12 08:33

    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", ")");
    

提交回复
热议问题