Skip to content

Instantly share code, notes, and snippets.

@Biseamon
Created February 19, 2020 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Biseamon/ef5e4ff015ff5cec003f81e35be973c0 to your computer and use it in GitHub Desktop.
Save Biseamon/ef5e4ff015ff5cec003f81e35be973c0 to your computer and use it in GitHub Desktop.
Polyline parser
public void prs(String s){
PolylineOptions polylineOptions = new PolylineOptions();
List<LatLng> movements = new ArrayList<>();
// List<String> points = new ArrayList<>();
String point = "";
try {
JSONObject json = new JSONObject(s);
JSONArray jsonRoute = json.getJSONArray("routes");
int count = jsonRoute.length();
for (int i = 0; i < count; i++) {
JSONObject jsonObject = jsonRoute.getJSONObject(i);
JSONArray jsonArray = jsonObject.getJSONArray("legs");
int count1 = jsonArray.length();
for (int j = 0; j < count1; j++) {
JSONObject jsonObject1 =jsonArray.getJSONObject(j);
JSONArray jsonArray1 = jsonObject1.getJSONArray("steps");
int count2 = jsonArray1.length();
for (int k = 0; k < count2; k++) {
JSONObject jsonObject2 = jsonArray1.getJSONObject(i);
point = jsonObject2.getJSONObject("polyline").getString("points");
movements.addAll(PolyUtil.decode(point));
}
}
}
polylineOptions.color(Color.RED);
polylineOptions.width(10);
polylineOptions.addAll(movements);
mMap.clear();
mMap.addPolyline(polylineOptions);
Log.i("parser", "parseDirect: " + movements.toString());
} catch (JSONException e) {
Log.d("error1", "prs: " + e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment