From 4566bf3cfb213b423770f490e46153b04a01b981 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Sun, 22 May 2016 22:49:02 -0300 Subject: [PATCH] Navitia: Find products for nearby stations --- .../schildbach/pte/AbstractNavitiaProvider.java | 15 +++++++++++++-- enabler/src/de/schildbach/pte/dto/Location.java | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/enabler/src/de/schildbach/pte/AbstractNavitiaProvider.java b/enabler/src/de/schildbach/pte/AbstractNavitiaProvider.java index e89f2fd3..614e7ed0 100644 --- a/enabler/src/de/schildbach/pte/AbstractNavitiaProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractNavitiaProvider.java @@ -257,7 +257,18 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider if (admin.length() > 0) place = Strings.emptyToNull(admin.getJSONObject(0).optString("name")); } - return new Location(type, id, point, place, name); + Set products = null; + if (location.has("stop_area") && location.getJSONObject("stop_area").has("physical_modes")) + { + products = EnumSet.noneOf(Product.class); + JSONArray physicalModes = location.getJSONObject("stop_area").getJSONArray("physical_modes"); + for (int i = 0; i < physicalModes.length(); i++) { + JSONObject mode = physicalModes.getJSONObject(i); + Product product = parseLineProductFromMode(mode.getString("id")); + if (product != null) products.add(product); + } + } + return new Location(type, id, point, place, name, products); } catch (final JSONException jsonExc) { @@ -853,7 +864,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider queryUri.append("&distance=").append(maxDistance); if (maxLocations > 0) queryUri.append("&count=").append(maxLocations); - queryUri.append("&depth=0"); + queryUri.append("&depth=3"); final CharSequence page = httpClient.get(queryUri.toString()); try diff --git a/enabler/src/de/schildbach/pte/dto/Location.java b/enabler/src/de/schildbach/pte/dto/Location.java index a0f3832c..d96b11af 100644 --- a/enabler/src/de/schildbach/pte/dto/Location.java +++ b/enabler/src/de/schildbach/pte/dto/Location.java @@ -70,6 +70,11 @@ public final class Location implements Serializable this(type, id, lat, lon, place, name, null); } + public Location(final LocationType type, final String id, final Point coord, final String place, final String name, final Set products) + { + this(type, id, coord != null ? coord.lat : 0, coord != null ? coord.lon : 0, place, name, products); + } + public Location(final LocationType type, final String id, final Point coord, final String place, final String name) { this(type, id, coord != null ? coord.lat : 0, coord != null ? coord.lon : 0, place, name);