Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Parsing the response from api.
- * TODO note to the backend - in response should be the coordinates of the returned area.
- * This would easiely allow you to detect any problems with the map (gps or network problem etc.)
- */
- public Roads parseRoads(String response) {
- Roads roads = new Roads();
- try {
- JSONArray ja = new JSONObject(response).getJSONArray(FEATURES);
- for (int i=0;i<ja.length();i++) {
- Road road = new Road();
- JSONObject jo = ja.getJSONObject(i);
- JSONObject geometry = jo.getJSONObject(GEOMETRY);
- JSONObject prop = jo.getJSONObject(PROPERTIES);
- if (prop.has(CATEGORY)) road.category = prop.getString(CATEGORY);
- if (prop.has(DIRECTION)) road.direction = prop.getInt(DIRECTION);
- try {
- if (prop.has(SPEED_LIMIT_ALONG)) road.speedLimitAlong = prop.getInt(SPEED_LIMIT_ALONG);
- } catch (Exception e) {
- //e.printStackTrace();
- road.speedLimitAlong = SPEED_LIMIT_NO_VALUE;
- }
- try {
- if (prop.has(SPEED_LIMIT_AGAINST)) road.speedLimitAgainst = prop.getInt(SPEED_LIMIT_AGAINST);
- } catch (Exception e) {
- //e.printStackTrace();
- road.speedLimitAgainst = SPEED_LIMIT_NO_VALUE;
- }
- JSONArray cord = geometry.getJSONArray(COORDINATES);
- for (int j=0;j<cord.length();j++) {
- double lon = cord.getJSONArray(j).getDouble(0);
- double lat = cord.getJSONArray(j).getDouble(1);
- road.coordinates.add(new Place(lon,lat));
- }
- roads.add(road);
- }
- } catch (JSONException e) {
- Log.e(TAG, "parseRoads: "+e.getMessage());
- e.printStackTrace();
- }
- return roads;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement