look up geolocation by station

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@18 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-07-21 08:09:52 +00:00
parent f505d2eda8
commit dc788b9985
6 changed files with 81 additions and 0 deletions

View file

@ -98,6 +98,36 @@ public class RmvProvider implements NetworkProvider
return stations.subList(0, maxStations);
}
private static Pattern P_STATION_LOCATION = Pattern
.compile("REQMapRoute0\\.Location0\\.X=(\\d+)&REQMapRoute0\\.Location0\\.Y=(\\d+)&REQMapRoute0\\.Location0\\.Name=(.+?)\"");
public StationLocationResult stationLocation(final String stationId) throws IOException
{
final String uri = "http://www.rmv.de/auskunft/bin/jp/stboard.exe/dn?L=vs_rmv&selectDate=today&time=now&showStBoard=yes&boardType=dep&maxJourneys=10&start&input="
+ stationId;
final CharSequence page = ParserUtils.scrape(uri);
final Matcher m = P_STATION_LOCATION.matcher(page);
if (m.find())
{
final double lon = latLonToDouble(Integer.parseInt(m.group(1)));
final double lat = latLonToDouble(Integer.parseInt(m.group(2)));
final String name = ParserUtils.resolveEntities(m.group(3));
return new StationLocationResult(lat, lon, name);
}
else
{
throw new IllegalArgumentException("cannot parse '" + page + "' on " + uri);
}
}
private static double latLonToDouble(int value)
{
return (double) value / 1000000;
}
public String connectionsQueryUri(final String from, final String via, final String to, final Date date, final boolean dep)
{
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");