Skip to content

Instantly share code, notes, and snippets.

@pratamawijaya
Created July 30, 2013 14:05
Show Gist options
  • Save pratamawijaya/6113194 to your computer and use it in GitHub Desktop.
Save pratamawijaya/6113194 to your computer and use it in GitHub Desktop.
method getDistance dan getDuration yang ditambahkan pada file JSONAdapter.java
public String getDistance(JSONObject jsonObject)
{
String distance = null;
try
{
JSONObject objRoute = jObj.getJSONArray(TAG_ROUTES).getJSONObject(0);
Utils.TRACE("get Routes");
JSONObject objLegs = objRoute.getJSONArray(TAG_LEGS).getJSONObject(0);
Utils.TRACE("get Legs");
JSONObject objDistance = objLegs.getJSONObject(TAG_DISTANCE);
distance = objDistance.getString(TAG_TEXT);
Utils.TRACE("distance :" + distance);
} catch (JSONException e)
{
// TODO: handle exception
Utils.TRACE("JSON distance gagal : " + e.toString());
}
return distance;
}
public String getDuration(JSONObject jsonObject)
{
String duration = null;
try
{
JSONObject objRoute = jObj.getJSONArray(TAG_ROUTES).getJSONObject(0);
Utils.TRACE("get Routes");
JSONObject objLegs = objRoute.getJSONArray(TAG_LEGS).getJSONObject(0);
Utils.TRACE("get Legs");
JSONObject objDistance = objLegs.getJSONObject(TAG_DURATION);
duration = objDistance.getString(TAG_TEXT);
Utils.TRACE("duration :" + duration);
} catch (JSONException e)
{
// TODO: handle exception
Utils.TRACE("JSON duration gagal : " + e.toString());
}
return duration;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment