Пример #1
0
  private static PolylineList ok(JSONArray routesArray) throws JSONException {

    JSONObject route = routesArray.getJSONObject(0);

    PolylineList polylineList = new PolylineList();
    polylineList.status = PolylineList.Status.OK;

    JSONArray legs = route.getJSONArray(Param.LEGS.toString());
    JSONObject leg = legs.getJSONObject(0);

    JSONObject distanceObj = leg.getJSONObject(Param.DISTANCE.toString());
    polylineList.distance = distanceObj.getLong(Param.VALUE.toString());

    JSONObject durationObj = leg.getJSONObject(Param.DURATION.toString());

    // содержит куб выделения информационного окна для маршрута.
    JSONObject bounds = route.getJSONObject(Param.BOUNDS.toString());
    JSONObject bounds_southwest = bounds.getJSONObject(Param.SOUTHWEST.toString());
    JSONObject bounds_northeast = bounds.getJSONObject(Param.NORTHEAAST.toString());

    double latitudeMax = bounds_northeast.getDouble(Param.LAT.toString());
    double longitudeMax = bounds_northeast.getDouble(Param.LNG.toString());
    double latitudeMin = bounds_southwest.getDouble(Param.LAT.toString());
    double longitudeMin = bounds_southwest.getDouble(Param.LNG.toString());
    polylineList.maxLatLng = new LatLng(latitudeMax, longitudeMax);
    polylineList.minLatLng = new LatLng(latitudeMin, longitudeMin);

    JSONArray steps = leg.getJSONArray(Param.STEPS.toString());
    for (int i = 0; i < steps.length(); i++) {
      JSONObject step = steps.getJSONObject(i);
      JSONObject start_location = step.getJSONObject(Param.START_LOCATION.toString());
      JSONObject end_location = step.getJSONObject(Param.END_LOCATION.toString());

      double latitudeStart = start_location.getDouble(Param.LAT.toString());
      double longitudeStart = start_location.getDouble(Param.LNG.toString());
      double latitudeEnd = end_location.getDouble(Param.LAT.toString());
      double longitudeEnd = end_location.getDouble(Param.LNG.toString());
      LatLng startGeoPoint = new LatLng(latitudeStart, longitudeStart);
      LatLng endGeoPoint = new LatLng(latitudeEnd, longitudeEnd);
      JSONObject polylineObject = step.getJSONObject(Param.POLYLINE.toString());

      // if(accuracyRoute == FINE_ROUTE ){
      List points = decodePoly(polylineObject.getString(Param.POINTS.toString()));
      polylineList.addAll(points);
      //                } else {
      //                    polyline.add(startGeoPoint);
      //                    polyline.add(endGeoPoint);
      //                }

    }
    return polylineList;
  }