Skip to content

Commit 3247ac9

Browse files
Merge pull request googlemaps#385 from domesticmouse/master
Adding strictbounds to Places Autocomplete
2 parents 9758c30 + 2cb1a96 commit 3247ac9

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/main/java/com/google/maps/PlaceAutocompleteRequest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,23 @@ public PlaceAutocompleteRequest radius(int radius) {
9393
*
9494
* @param type The type to restrict results to.
9595
* @return Returns this {@code PlaceAutocompleteRequest} for call chaining.
96+
* @deprecated Please use {@code types} instead.
9697
*/
9798
public PlaceAutocompleteRequest type(PlaceAutocompleteType type) {
98-
return param("types", type);
99+
return this.types(type);
99100
}
100101

102+
/**
103+
* Restricts the results to places matching the specified type.
104+
*
105+
* @param types The type to restrict results to.
106+
* @return Returns this {@code PlaceAutocompleteRequest} for call chaining.
107+
*/
108+
public PlaceAutocompleteRequest types(PlaceAutocompleteType types) {
109+
return param("types", types);
110+
}
111+
112+
101113
/**
102114
* A grouping of places to which you would like to restrict your results. Currently, you can use
103115
* components to filter by country.
@@ -109,6 +121,18 @@ public PlaceAutocompleteRequest components(ComponentFilter... filters) {
109121
return param("components", join('|', filters));
110122
}
111123

124+
/**
125+
* StrictBounds returns only those places that are strictly within the region defined by location
126+
* and radius. This is a restriction, rather than a bias, meaning that results outside this region
127+
* will not be returned even if they match the user input.
128+
*
129+
* @param strictBounds Whether to strictly bound results.
130+
* @return Returns this {@code PlaceAutocompleteRequest} for call chaining.
131+
*/
132+
public PlaceAutocompleteRequest strictBounds(boolean strictBounds) {
133+
return param("strictbounds", Boolean.toString(strictBounds).toString());
134+
}
135+
112136
@Override
113137
protected void validateRequest() {
114138
if (!params().containsKey("input")) {

src/test/java/com/google/maps/PlacesApiTest.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ public void testPlaceAutocompleteRequest() throws Exception {
651651
.offset(4)
652652
.location(location)
653653
.radius(5000)
654-
.type(PlaceAutocompleteType.ESTABLISHMENT)
654+
.types(PlaceAutocompleteType.ESTABLISHMENT)
655655
.components(ComponentFilter.country("AU"))
656656
.await();
657657

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

851851
sc.assertParamValue("po", "input");
@@ -862,6 +862,25 @@ public void testPlaceAutocompleteWithType() throws Exception {
862862
}
863863
}
864864

865+
@Test
866+
public void testPlaceAutocompleteWithStrictBounds() throws Exception {
867+
try (LocalTestServerContext sc = new LocalTestServerContext(placesApiPlaceAutocomplete)) {
868+
AutocompletePrediction[] predictions =
869+
PlacesApi.placeAutocomplete(sc.context, "Amoeba")
870+
.types(PlaceAutocompleteType.ESTABLISHMENT)
871+
.location(new LatLng(37.76999,-122.44696))
872+
.radius(500)
873+
.strictBounds(true)
874+
.await();
875+
876+
sc.assertParamValue("Amoeba", "input");
877+
sc.assertParamValue("establishment", "types");
878+
sc.assertParamValue("37.76999000,-122.44696000","location");
879+
sc.assertParamValue("500", "radius");
880+
sc.assertParamValue("true", "strictbounds");
881+
}
882+
}
883+
865884
@Test
866885
public void testKitaWard() throws Exception {
867886
try (LocalTestServerContext sc = new LocalTestServerContext(placesApiKitaWard)) {

0 commit comments

Comments
 (0)