diff --git a/src/de/schildbach/pte/BahnProvider.java b/src/de/schildbach/pte/BahnProvider.java index 36cc4438..ae2a369f 100644 --- a/src/de/schildbach/pte/BahnProvider.java +++ b/src/de/schildbach/pte/BahnProvider.java @@ -110,6 +110,11 @@ public final class BahnProvider implements NetworkProvider { return (double) value / 1000000; } + + public StationLocationResult stationLocation(final String stationId) throws IOException + { + throw new UnsupportedOperationException(); + } public String connectionsQueryUri(final String from, final String via, final String to, final Date date, final boolean dep) { diff --git a/src/de/schildbach/pte/MvvProvider.java b/src/de/schildbach/pte/MvvProvider.java index 410878ea..1b144a12 100644 --- a/src/de/schildbach/pte/MvvProvider.java +++ b/src/de/schildbach/pte/MvvProvider.java @@ -78,6 +78,11 @@ public class MvvProvider implements NetworkProvider throw new UnsupportedOperationException(); } + public StationLocationResult stationLocation(final String stationId) throws IOException + { + throw new UnsupportedOperationException(); + } + public String connectionsQueryUri(final String from, final String via, final String to, final Date date, final boolean dep) { final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd"); diff --git a/src/de/schildbach/pte/NetworkProvider.java b/src/de/schildbach/pte/NetworkProvider.java index 3b19d600..d6351a47 100644 --- a/src/de/schildbach/pte/NetworkProvider.java +++ b/src/de/schildbach/pte/NetworkProvider.java @@ -61,6 +61,8 @@ public interface NetworkProvider */ List nearbyStations(double lat, double lon, int maxDistance, int maxStations) throws IOException; + StationLocationResult stationLocation(String stationId) throws IOException; + /** * Construct an Uri for querying connections * diff --git a/src/de/schildbach/pte/RmvProvider.java b/src/de/schildbach/pte/RmvProvider.java index 890b285e..b4d6905f 100644 --- a/src/de/schildbach/pte/RmvProvider.java +++ b/src/de/schildbach/pte/RmvProvider.java @@ -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"); diff --git a/src/de/schildbach/pte/StationLocationResult.java b/src/de/schildbach/pte/StationLocationResult.java new file mode 100644 index 00000000..fdf8cb39 --- /dev/null +++ b/src/de/schildbach/pte/StationLocationResult.java @@ -0,0 +1,34 @@ +/* + * Copyright 2010 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.schildbach.pte; + +/** + * @author Andreas Schildbach + */ +public final class StationLocationResult +{ + public final double lat, lon; + public final String name; + + public StationLocationResult(final double lat, final double lon, final String name) + { + this.lat = lat; + this.lon = lon; + this.name = name; + } +} diff --git a/src/de/schildbach/pte/VbbProvider.java b/src/de/schildbach/pte/VbbProvider.java index b42b1339..6964489f 100644 --- a/src/de/schildbach/pte/VbbProvider.java +++ b/src/de/schildbach/pte/VbbProvider.java @@ -98,6 +98,11 @@ public final class VbbProvider implements NetworkProvider throw new UnsupportedOperationException(); } + public StationLocationResult stationLocation(final String stationId) throws IOException + { + throw new UnsupportedOperationException(); + } + public static final String STATION_URL_CONNECTION = "http://mobil.bvg.de/Fahrinfo/bin/query.bin/dox"; public String connectionsQueryUri(final String from, final String via, final String to, final Date date, final boolean dep)