queryNearbyStations now takes Location object

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@619 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-05-07 16:29:02 +00:00
parent c0f0be81bf
commit 653d590e1b
112 changed files with 605 additions and 501 deletions

View file

@ -81,33 +81,28 @@ public final class BahnProvider extends AbstractHafasProvider
private final static Pattern P_NEARBY_STATIONS_BY_STATION = Pattern
.compile("<a href=\"http://mobile\\.bahn\\.de/bin/mobil/bhftafel.exe/dn[^\"]*?evaId=(\\d*)&[^\"]*?\">([^<]*)</a>");
@Override
protected String nearbyStationUri(final String stationId)
{
throw new UnsupportedOperationException();
}
@Override
public NearbyStationsResult nearbyStations(final String stationId, final int lat, final int lon, final int maxDistance, final int maxStations)
throws IOException
public NearbyStationsResult queryNearbyStations(final Location location, final int maxDistance, final int maxStations) throws IOException
{
final StringBuilder uri = new StringBuilder(API_BASE);
if (lat != 0 || lon != 0)
if (location.hasLocation())
{
uri.append("query.exe/dny");
uri.append("?performLocating=2&tpl=stop2json");
uri.append("&look_maxno=").append(maxStations != 0 ? maxStations : 200);
uri.append("&look_maxdist=").append(maxDistance != 0 ? maxDistance : 5000);
uri.append("&look_stopclass=").append(allProductsInt());
uri.append("&look_x=").append(lon);
uri.append("&look_y=").append(lat);
uri.append("&look_x=").append(location.lon);
uri.append("&look_y=").append(location.lat);
return jsonNearbyStations(uri.toString());
}
else
else if (location.type == LocationType.STATION && location.hasId())
{
uri.append("bhftafel.exe/dn?near=Anzeigen&distance=50&input=").append(ParserUtils.urlEncode(stationId));
uri.append("bhftafel.exe/dn");
uri.append("?near=Anzeigen");
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
uri.append("&input=").append(location.id);
final CharSequence page = ParserUtils.scrape(uri.toString());
@ -128,6 +123,10 @@ public final class BahnProvider extends AbstractHafasProvider
else
return new NearbyStationsResult(stations.subList(0, maxStations));
}
else
{
throw new IllegalArgumentException("cannot handle: " + location.toDebugString());
}
}
private String connectionsQueryUri(final Location from, final Location via, final Location to, final Date date, final boolean dep,