Created
February 19, 2020 15:15
-
-
Save Biseamon/ef5e4ff015ff5cec003f81e35be973c0 to your computer and use it in GitHub Desktop.
Polyline 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"); | |
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