Navitia: Also suggest POI and administrative locations

The administrative areas are extremely useful when people search for a
suburb, but no stops have the suburbs name. They are currently mapped
to a POI location.
This commit is contained in:
Torsten Grote 2016-03-14 20:30:51 -03:00 committed by Andreas Schildbach
parent 889a85b745
commit 2adf627e51
3 changed files with 47 additions and 2 deletions

View file

@ -211,7 +211,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider
}
case POI:
{
return LocationType.ANY;
return LocationType.POI;
}
default:
throw new IllegalArgumentException("Unhandled place type: " + placeType);
@ -257,6 +257,21 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider
}
}
private Location parseAdministrativeRegion(final JSONObject j) throws IOException
{
try
{
final JSONObject coord = j.getJSONObject("coord");
final Point point = parseCoord(coord);
final String name = j.getString("name");
return new Location(LocationType.POI, null, point, null, name);
}
catch (final JSONException jsonExc)
{
throw new ParserException(jsonExc);
}
}
private Location parseLocation(final JSONObject j) throws IOException
{
try
@ -287,6 +302,10 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider
location = j.getJSONObject("poi");
break;
}
case ADMINISTRATIVE_REGION:
{
return parseAdministrativeRegion(j.getJSONObject("administrative_region"));
}
default:
throw new IllegalArgumentException("Unhandled place type: " + type);
}
@ -1029,7 +1048,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider
{
final String nameCstr = constraint.toString();
final String queryUri = uri() + "places?q=" + ParserUtils.urlEncode(nameCstr) + "&type[]=stop_area&type[]=address" + "&depth=1";
final String queryUri = uri() + "places?q=" + ParserUtils.urlEncode(nameCstr) + "&type[]=stop_area&type[]=address&type[]=poi&type[]=administrative_region" + "&depth=1";
final CharSequence page = httpClient.get(queryUri);
try

View file

@ -250,6 +250,26 @@ public abstract class AbstractNavitiaProviderLiveTest extends AbstractProviderLi
print(result);
}
protected final void queryTripFromAdminToPoi(final CharSequence from, final CharSequence to) throws IOException
{
final SuggestLocationsResult fromResult = suggestLocations(from);
assertTrue(fromResult.getLocations().size() > 0);
Location fromLocation = fromResult.getLocations().get(0);
assertEquals(fromLocation.type, LocationType.POI);
print(fromResult);
final SuggestLocationsResult toResult = suggestLocations(to);
assertTrue(toResult.getLocations().size() > 0);
Location toLocation = toResult.getLocations().get(0);
assertEquals(toLocation.type, LocationType.POI);
print(toResult);
final QueryTripsResult tripsResult = queryTrips(fromLocation, null, toLocation, new Date(), true,
Product.ALL, NetworkProvider.WalkSpeed.NORMAL, NetworkProvider.Accessibility.NEUTRAL);
assertEquals(QueryTripsResult.Status.OK, tripsResult.status);
print(tripsResult);
}
protected final void queryMoreTrips(final CharSequence from, final CharSequence to) throws IOException
{
final SuggestLocationsResult fromResult = suggestLocations(from);

View file

@ -154,6 +154,12 @@ public class ParisProviderLiveTest extends AbstractNavitiaProviderLiveTest
queryTrip("Luxembourg Paris", "Antony Antony");
}
@Test
public void queryTripFromAdministrativeRegionToPoi() throws Exception
{
queryTripFromAdminToPoi("Paris 10e Arrondissement", "Paris Tour Eiffel");
}
@Test
public void queryTripNoSolution() throws Exception
{