mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-10 15:48:49 +00:00
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:
parent
f505d2eda8
commit
dc788b9985
6 changed files with 81 additions and 0 deletions
|
@ -111,6 +111,11 @@ public final class BahnProvider implements NetworkProvider
|
||||||
return (double) value / 1000000;
|
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)
|
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");
|
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||||
|
|
|
@ -78,6 +78,11 @@ public class MvvProvider implements NetworkProvider
|
||||||
throw new UnsupportedOperationException();
|
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)
|
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");
|
final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
|
|
@ -61,6 +61,8 @@ public interface NetworkProvider
|
||||||
*/
|
*/
|
||||||
List<Station> nearbyStations(double lat, double lon, int maxDistance, int maxStations) throws IOException;
|
List<Station> nearbyStations(double lat, double lon, int maxDistance, int maxStations) throws IOException;
|
||||||
|
|
||||||
|
StationLocationResult stationLocation(String stationId) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an Uri for querying connections
|
* Construct an Uri for querying connections
|
||||||
*
|
*
|
||||||
|
|
|
@ -98,6 +98,36 @@ public class RmvProvider implements NetworkProvider
|
||||||
return stations.subList(0, maxStations);
|
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)
|
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");
|
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||||
|
|
34
src/de/schildbach/pte/StationLocationResult.java
Normal file
34
src/de/schildbach/pte/StationLocationResult.java
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -98,6 +98,11 @@ public final class VbbProvider implements NetworkProvider
|
||||||
throw new UnsupportedOperationException();
|
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 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)
|
public String connectionsQueryUri(final String from, final String via, final String to, final Date date, final boolean dep)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue