draw a map from encoded polylines

المشرف العام

Administrator
طاقم الإدارة
I'm using the google maps web services service to find a route. From the json response I parse it encoded polylines and store it on coordinates String.

private String parseJson(String s){ String coordinates = new String (); final JSONObject json = new JSONObject(s); final JSONObject jsonRoute = json.getJSONArray("routes").getJSONObject(0); //Get the leg, only one leg as we don't support waypoints final JSONObject leg = jsonRoute.getJSONArray("legs").getJSONObject(0); //Get the steps for this leg final JSONArray steps = leg.getJSONArray("steps"); //Number of steps for use in for loop final int numSteps = steps.length(); for(int i = 0; i< numSteps; ++i){ final JSONObject step = steps.getJSONObject(i); final JSONObject startLocation = step.getJSONObject("start_location"); final JSONObject polyline = step.getJSONObject("polyline"); final String polylinePoint = polyline.getString("points"); coordinates = coordinates.concat(polylinePoint); } return coordinates; }Then, coordinates is passed as parameter to decoded function, which gives a list of {Latitude,Longitude}

encodedPath = parseJson(str); List list = decodePath(encodedPath); String path = encodedPath(list);The problem is that reading all polylines and storing it on String, then decoding it ends that a new encoding, to generate a URL, igual the original str.



أكثر...
 
أعلى