List<TimedPlaceBean> beans = new ArrayList<TimedPlaceBean>();
double walkingVelocity = travelTimes.getWalkingVelocity() / 1000;
ConstraintsBean walkConstraints = new ConstraintsBean(constraints);
walkConstraints.setModes(CollectionsLibrary.set(Modes.WALK));
for (LocalSearchResult result : localResults) {
double placeLat = result.getLat();
double placeLon = result.getLon();
List<TripToStop> closestStops = new ArrayList<TripToStop>();
for (int index = 0; index < travelTimes.getSize(); index++) {
String stopIdAsString = travelTimes.getStopId(index);
AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(stopIdAsString);
long currentTripDuration = travelTimes.getTravelTime(index);
double stopLat = travelTimes.getStopLat(index);
double stopLon = travelTimes.getStopLon(index);
double d = SphericalGeometryLibrary.distance(stopLat, stopLon,
placeLat, placeLon);
double t = currentTripDuration + d / walkingVelocity;
if (d <= constraints.getMaxWalkingDistance() && t < maxTripLength) {
closestStops.add(new TripToStop(stopId, currentTripDuration, t, index));
}
}
if (closestStops.isEmpty())
continue;
Collections.sort(closestStops);
double minTime = 0;
TripToStop minStop = null;
TransitLocationBean place = new TransitLocationBean();
place.setLat(result.getLat());
place.setLon(result.getLon());
for (TripToStop o : closestStops) {
long currentTripDuration = o.getTransitTimeToStop();
double minTimeToPlace = o.getMinTansitTimeToPlace();
// Short circuit if there is no way any of the remaining trips is going
// to be better than our current winner
if (minStop != null && minTimeToPlace > minTime)
break;
int remainingTime = (int) ((maxTripLength - currentTripDuration) / 1000);
walkConstraints.setMaxTripDuration(remainingTime);
int index = o.getIndex();
TransitLocationBean stopLocation = new TransitLocationBean();
stopLocation.setLat(travelTimes.getStopLat(index));
stopLocation.setLon(travelTimes.getStopLon(index));