Created
February 18, 2020 23:27
-
-
Save Biseamon/64515eefec707a9c3cb4fcc38dec56a1 to your computer and use it in GitHub Desktop.
JSON polyline points parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
JSONObject jsonObject1 = jsonArray.getJSONObject(i); | |
JSONArray jsonArray1 = jsonObject1.getJSONArray("steps"); | |
int count1 = jsonArray1.length(); | |
for (int j = 0; j < count1; j++) { | |
JSONObject jsonObject2 = jsonArray1.getJSONObject(i); | |
point = jsonObject2.getJSONObject("polyline").getString("points"); | |
points.add(point); | |
} | |
movements.addAll(PolyUtil.decode(String.valueOf(points))); | |
polylineOptions.width(10).color(Color.RED); | |
polylineOptions.addAll(movements); | |
mMap.clear(); | |
mMap.addPolyline(polylineOptions); | |
Log.i("prs", "prs: " + movements.toString()); | |
} | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment