@Override
 public void handleEvent(PersonArrivalEvent event) {
   try {
     if (isTransitScenario) {
       if (transitDriverIds.contains(event.getPersonId())) return;
     }
     TravellerChain chain = chains.get(event.getPersonId());
     switch (event.getLegMode()) {
       case "walk":
       case "transit_walk":
         {
           Journey journey = chain.getJourneys().getLast();
           Walk walk = journey.getWalks().getLast();
           walk.setDest(network.getLinks().get(event.getLinkId()).getCoord());
           walk.setEndTime(event.getTime());
           walk.setDistance(walk.getDuration() * walkSpeed);
           break;
         }
       case TransportMode.car:
         {
           Journey journey = chain.getJourneys().getLast();
           journey.setDest(network.getLinks().get(event.getLinkId()).getCoord());
           journey.setEndTime(event.getTime());
           Trip trip = journey.getTrips().getLast();
           trip.setDistance(journey.getDistance());
           trip.setEndTime(event.getTime());
           chain.inCar = false;
           break;
         }
       case "pt":
         if (isTransitScenario) {
           Journey journey = chain.getJourneys().getLast();
           Trip trip = journey.getTrips().getLast();
           trip.setDest(network.getLinks().get(event.getLinkId()).getCoord());
           trip.setEndTime(event.getTime());
           journey.setPossibleTransfer(new Transfer());
           journey.getPossibleTransfer().setStartTime(event.getTime());
           journey.getPossibleTransfer().setFromTrip(trip);
         } else {
           Journey journey = chain.getJourneys().getLast();
           journey.setEndTime(event.getTime());
           journey.setDest(network.getLinks().get(event.getLinkId()).getCoord());
           journey.setEndTime(event.getTime());
         }
         break;
       default:
         Journey journey = chain.getJourneys().getLast();
         journey.setEndTime(event.getTime());
         journey.setDest(network.getLinks().get(event.getLinkId()).getCoord());
         journey.setEndTime(event.getTime());
         break;
     }
   } catch (Exception e) {
     System.err.println(e.getStackTrace());
     System.err.println(event.toString());
   }
 }
  /**
   * Parses a url pointing to a Google JSON object to a Route object.
   *
   * @throws Exception
   */
  private void parse() throws Exception {
    String response = getUrlContent(result);

    JSONObject jObject = new JSONObject(response);
    status = jObject.getString("status");

    // checks to make sure there are no errors in getting content.
    if (checkStatus(status) == 0) {
      // drills down the JSON object to find each individual step.
      JSONObject jsonRoute = jObject.getJSONArray("routes").getJSONObject(0);
      JSONObject leg = jsonRoute.getJSONArray("legs").getJSONObject(0);
      JSONObject tripDistObj = leg.getJSONObject("distance");
      JSONObject tripDurObj = leg.getJSONObject("duration");
      int distance = tripDistObj.getInt("value");
      int duration = tripDurObj.getInt("value");
      JSONArray steps = leg.getJSONArray("steps");
      routes = new Route[steps.length()];

      for (int i = 0; i < steps.length(); i++) {
        // updates more information about route for each step in trip in a array of routes.
        JSONObject step = steps.getJSONObject(i);
        routes[i] = new Route();
        routes[i].setInstruction(step.getString("html_instructions"));
        routes[i].setDuration((step.getJSONObject("duration").getInt("value")));
        routes[i].setStartLoc(
            new Location(
                step.getJSONObject("start_location").getDouble("lat"),
                step.getJSONObject("start_location").getDouble("lng")));
        routes[i].setEndLoc(
            new Location(
                step.getJSONObject("end_location").getDouble("lat"),
                step.getJSONObject("end_location").getDouble("lng")));
        // Get google's copyright notice (requirement)
        routes[i].setCopyright(jsonRoute.getString("copyrights"));
        // Get the total length of this step.
        routes[i].setLength(step.getJSONObject("distance").getInt("value"));
        // Get any warnings provided (requirement)
        if (!jsonRoute.getJSONArray("warnings").isNull(0)) {
          routes[i].setWarning(jsonRoute.getJSONArray("warnings").getString(0));
        }
      }
      trip = new Trip();
      trip.setRoute(routes);
      trip.setDuration(duration);
      trip.setDistance(distance);
    }
  }
  @Override
  public void handleEvent(PersonLeavesVehicleEvent event) {
    if (transitDriverIds.contains(event.getPersonId())) return;
    try {
      if (ptVehicles.keySet().contains(event.getVehicleId())) {
        TravellerChain chain = chains.get(event.getPersonId());
        chain.traveledVehicle = true;
        PTVehicle vehicle = ptVehicles.get(event.getVehicleId());
        double stageDistance = vehicle.removePassenger(event.getPersonId());
        Trip trip = chain.getJourneys().getLast().getTrips().getLast();
        trip.setDistance(stageDistance);
        trip.setAlightingStop(vehicle.lastStop);
      } else {
        driverIdFromVehicleId.remove(event.getVehicleId());
      }

    } catch (Exception e) {
      System.err.println(e.getStackTrace());
      System.err.println(event.toString());
    }
  }