Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding strictbounds to Places Autocomplete #385

Merged
merged 1 commit into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/main/java/com/google/maps/PlaceAutocompleteRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,23 @@ public PlaceAutocompleteRequest radius(int radius) {
*
* @param type The type to restrict results to.
* @return Returns this {@code PlaceAutocompleteRequest} for call chaining.
* @deprecated Please use {@code types} instead.
*/
public PlaceAutocompleteRequest type(PlaceAutocompleteType type) {
return param("types", type);
return this.types(type);
}

/**
* Restricts the results to places matching the specified type.
*
* @param types The type to restrict results to.
* @return Returns this {@code PlaceAutocompleteRequest} for call chaining.
*/
public PlaceAutocompleteRequest types(PlaceAutocompleteType types) {
return param("types", types);
}


/**
* A grouping of places to which you would like to restrict your results. Currently, you can use
* components to filter by country.
Expand All @@ -109,6 +121,18 @@ public PlaceAutocompleteRequest components(ComponentFilter... filters) {
return param("components", join('|', filters));
}

/**
* StrictBounds returns only those places that are strictly within the region defined by location
* and radius. This is a restriction, rather than a bias, meaning that results outside this region
* will not be returned even if they match the user input.
*
* @param strictBounds Whether to strictly bound results.
* @return Returns this {@code PlaceAutocompleteRequest} for call chaining.
*/
public PlaceAutocompleteRequest strictBounds(boolean strictBounds) {
return param("strictbounds", Boolean.toString(strictBounds).toString());
}

@Override
protected void validateRequest() {
if (!params().containsKey("input")) {
Expand Down
23 changes: 21 additions & 2 deletions src/test/java/com/google/maps/PlacesApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public void testPlaceAutocompleteRequest() throws Exception {
.offset(4)
.location(location)
.radius(5000)
.type(PlaceAutocompleteType.ESTABLISHMENT)
.types(PlaceAutocompleteType.ESTABLISHMENT)
.components(ComponentFilter.country("AU"))
.await();

Expand Down Expand Up @@ -845,7 +845,7 @@ public void testPlaceAutocompleteWithType() throws Exception {
AutocompletePrediction[] predictions =
PlacesApi.placeAutocomplete(sc.context, "po")
.components(ComponentFilter.country("nz"))
.type(PlaceAutocompleteType.REGIONS)
.types(PlaceAutocompleteType.REGIONS)
.await();

sc.assertParamValue("po", "input");
Expand All @@ -862,6 +862,25 @@ public void testPlaceAutocompleteWithType() throws Exception {
}
}

@Test
public void testPlaceAutocompleteWithStrictBounds() throws Exception {
try (LocalTestServerContext sc = new LocalTestServerContext(placesApiPlaceAutocomplete)) {
AutocompletePrediction[] predictions =
PlacesApi.placeAutocomplete(sc.context, "Amoeba")
.types(PlaceAutocompleteType.ESTABLISHMENT)
.location(new LatLng(37.76999,-122.44696))
.radius(500)
.strictBounds(true)
.await();

sc.assertParamValue("Amoeba", "input");
sc.assertParamValue("establishment", "types");
sc.assertParamValue("37.76999000,-122.44696000","location");
sc.assertParamValue("500", "radius");
sc.assertParamValue("true", "strictbounds");
}
}

@Test
public void testKitaWard() throws Exception {
try (LocalTestServerContext sc = new LocalTestServerContext(placesApiKitaWard)) {
Expand Down