Skip to content

Commit

Permalink
Merge pull request #385 from domesticmouse/master
Browse files Browse the repository at this point in the history
Adding strictbounds to Places Autocomplete
  • Loading branch information
domesticmouse authored Nov 14, 2017
2 parents 9758c30 + 2cb1a96 commit 3247ac9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
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

0 comments on commit 3247ac9

Please sign in to comment.