AbstractHafasClientInterfaceProvider: Support maxDistance when querying for nearby locations.

This commit is contained in:
Andreas Schildbach 2018-10-27 18:01:40 +02:00
parent 59e6438882
commit 06cec0c183
2 changed files with 10 additions and 8 deletions

View file

@ -129,7 +129,7 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location, public NearbyLocationsResult queryNearbyLocations(final EnumSet<LocationType> types, final Location location,
final int maxDistance, final int maxLocations) throws IOException { final int maxDistance, final int maxLocations) throws IOException {
if (location.hasLocation()) if (location.hasLocation())
return jsonLocGeoPos(types, location.lat, location.lon); return jsonLocGeoPos(types, location.lat, location.lon, maxDistance);
else else
throw new IllegalArgumentException("cannot handle: " + location); throw new IllegalArgumentException("cannot handle: " + location);
} }
@ -160,13 +160,14 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
jsonContext.products, jsonContext.walkSpeed, later ? jsonContext.laterContext : jsonContext.earlierContext); jsonContext.products, jsonContext.walkSpeed, later ? jsonContext.laterContext : jsonContext.earlierContext);
} }
protected final NearbyLocationsResult jsonLocGeoPos(final EnumSet<LocationType> types, final int lat, final int lon) protected final NearbyLocationsResult jsonLocGeoPos(final EnumSet<LocationType> types, final int lat, final int lon,
throws IOException { int maxDistance) throws IOException {
if (maxDistance == 0)
maxDistance = DEFAULT_MAX_DISTANCE;
final boolean getPOIs = types.contains(LocationType.POI); final boolean getPOIs = types.contains(LocationType.POI);
final String request = wrapJsonApiRequest("LocGeoPos", final String request = wrapJsonApiRequest("LocGeoPos", "{\"ring\":" //
"{\"ring\":" // + "{\"cCrd\":{\"x\":" + lon + ",\"y\":" + lat + "},\"maxDist\":" + maxDistance + "}," //
+ "{\"cCrd\":{\"x\":" + lon + ",\"y\":" + lat + "}}," // + "\"getPOIs\":" + getPOIs + "}", //
+ "\"getPOIs\":" + getPOIs + "}", //
false); false);
final HttpUrl url = requestUrl(request); final HttpUrl url = requestUrl(request);
@ -401,7 +402,7 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
} }
if (location.hasLocation()) { if (location.hasLocation()) {
final List<Location> locations = jsonLocGeoPos(EnumSet.allOf(LocationType.class), location.lat, final List<Location> locations = jsonLocGeoPos(EnumSet.allOf(LocationType.class), location.lat,
location.lon).locations; location.lon, 0).locations;
if (!locations.isEmpty()) if (!locations.isEmpty())
return locations.get(0); return locations.get(0);
} }

View file

@ -41,6 +41,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
protected static final String SERVER_PRODUCT = "hafas"; protected static final String SERVER_PRODUCT = "hafas";
protected static final int DEFAULT_MAX_DEPARTURES = 100; protected static final int DEFAULT_MAX_DEPARTURES = 100;
protected static final int DEFAULT_MAX_LOCATIONS = 50; protected static final int DEFAULT_MAX_LOCATIONS = 50;
protected static final int DEFAULT_MAX_DISTANCE = 20000;
protected static final Logger log = LoggerFactory.getLogger(AbstractHafasProvider.class); protected static final Logger log = LoggerFactory.getLogger(AbstractHafasProvider.class);