diff --git a/CONTRIBUTORS b/CONTRIBUTORS index ab7b0c88a..36aa20f69 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -10,6 +10,7 @@ Amy Boyd @amyboyd Brantley Wells @gitbrantley Brett Morgan @domesticmouse Chris Broadfoot @broady +Dan O'Meara @danoscarmike Dave Holmes @dh-- Ismael Blesa @ismamai Malcolm Windsor @mwindsor-beoped diff --git a/README.md b/README.md index 5d87d3ce5..78d20e211 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ Maven Central](https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22google-maps-se ## Developer Documentation -View the [javadoc](https://googlemaps.github.io/google-maps-services-java/v0.9.2/javadoc/index.html?overview-summary.html). +View the [javadoc](https://googlemaps.github.io/google-maps-services-java/v0.9.3/javadoc/index.html?overview-summary.html). Additional documentation for the included web services is available at https://developers.google.com/maps/. diff --git a/build.gradle b/build.gradle index b4787ff70..687803c8e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,13 +5,13 @@ buildscript { mavenCentral() } dependencies { - classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2' + classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.3' } } plugins { - id 'com.github.ben-manes.versions' version '0.21.0' + id 'com.github.ben-manes.versions' version '0.22.0' id 'com.github.sherter.google-java-format' version '0.8' } @@ -47,16 +47,16 @@ artifacts { } dependencies { - compileOnly 'com.google.appengine:appengine-api-1.0-sdk:1.9.71' - api 'com.squareup.okhttp3:okhttp:3.14.0' + compileOnly 'com.google.appengine:appengine-api-1.0-sdk:1.9.76' + api 'com.squareup.okhttp3:okhttp:3.14.2' api 'com.google.code.gson:gson:2.8.5' - implementation 'org.slf4j:slf4j-api:1.7.25' + implementation 'org.slf4j:slf4j-api:1.7.26' testImplementation 'junit:junit:4.12' - testImplementation 'org.mockito:mockito-core:2.25.1' - testImplementation 'com.squareup.okhttp3:mockwebserver:3.14.0' - testImplementation 'org.apache.httpcomponents:httpclient:4.5.7' - testImplementation 'org.slf4j:slf4j-simple:1.7.25' - testImplementation 'org.apache.commons:commons-lang3:3.8.1' + testImplementation 'org.mockito:mockito-core:3.0.0' + testImplementation 'com.squareup.okhttp3:mockwebserver:3.14.2' + testImplementation 'org.apache.httpcomponents:httpclient:4.5.9' + testImplementation 'org.slf4j:slf4j-simple:1.7.26' + testImplementation 'org.apache.commons:commons-lang3:3.9' testImplementation 'org.json:json:20180813' } diff --git a/gradle.properties b/gradle.properties index 9032223f2..207a978d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=0.9.3 +version=0.9.4 # variables required to allow build.gradle to parse, # override in ~/.gradle/gradle.properties diff --git a/src/main/java/com/google/maps/DirectionsApi.java b/src/main/java/com/google/maps/DirectionsApi.java index fe1eb48e9..e299b1163 100644 --- a/src/main/java/com/google/maps/DirectionsApi.java +++ b/src/main/java/com/google/maps/DirectionsApi.java @@ -63,7 +63,7 @@ public static DirectionsApiRequest getDirections( return new DirectionsApiRequest(context).origin(origin).destination(destination); } - static class Response implements ApiResponse { + public static class Response implements ApiResponse { public String status; public String errorMessage; public GeocodedWaypoint[] geocodedWaypoints; diff --git a/src/main/java/com/google/maps/DistanceMatrixApi.java b/src/main/java/com/google/maps/DistanceMatrixApi.java index e29da73d4..ddf9da9f1 100644 --- a/src/main/java/com/google/maps/DistanceMatrixApi.java +++ b/src/main/java/com/google/maps/DistanceMatrixApi.java @@ -53,7 +53,7 @@ public static DistanceMatrixApiRequest getDistanceMatrix( return newRequest(context).origins(origins).destinations(destinations); } - static class Response implements ApiResponse { + public static class Response implements ApiResponse { public String status; public String errorMessage; public String[] originAddresses; diff --git a/src/main/java/com/google/maps/GeocodingApi.java b/src/main/java/com/google/maps/GeocodingApi.java index 3b35cb555..b760ad15c 100644 --- a/src/main/java/com/google/maps/GeocodingApi.java +++ b/src/main/java/com/google/maps/GeocodingApi.java @@ -68,7 +68,7 @@ public static GeocodingApiRequest reverseGeocode(GeoApiContext context, LatLng l return request; } - static class Response implements ApiResponse { + public static class Response implements ApiResponse { public String status; public String errorMessage; public GeocodingResult[] results; diff --git a/src/main/java/com/google/maps/PlacesApi.java b/src/main/java/com/google/maps/PlacesApi.java index 9deb9ac3e..e51c34bb3 100644 --- a/src/main/java/com/google/maps/PlacesApi.java +++ b/src/main/java/com/google/maps/PlacesApi.java @@ -16,6 +16,7 @@ package com.google.maps; import com.google.maps.model.LatLng; +import com.google.maps.model.PlaceType; /** * Performs a text search for places. The Google Places API enables you to get data from the same @@ -73,6 +74,19 @@ public static TextSearchRequest textSearchQuery(GeoApiContext context, String qu return request; } + /** + * Performs a search for Places using a PlaceType parameter. + * + * @param context The context on which to make Geo API requests. + * @param type Restricts the results to places matching the specified PlaceType. + * @return Returns a TextSearchRequest that can be configured and executed. + */ + public static TextSearchRequest textSearchQuery(GeoApiContext context, PlaceType type) { + TextSearchRequest request = new TextSearchRequest(context); + request.type(type); + return request; + } + /** * Retrieves the next page of Text Search results. The nextPageToken, returned in a * PlacesSearchResponse when there are more pages of results, encodes all of the original Text diff --git a/src/main/java/com/google/maps/RoadsApi.java b/src/main/java/com/google/maps/RoadsApi.java index 246e4544b..67f72340c 100644 --- a/src/main/java/com/google/maps/RoadsApi.java +++ b/src/main/java/com/google/maps/RoadsApi.java @@ -163,7 +163,7 @@ public static PendingResult nearestRoads( return context.get(NEAREST_ROADS_API_CONFIG, RoadsResponse.class, "points", join('|', points)); } - private static class RoadsResponse implements ApiResponse { + public static class RoadsResponse implements ApiResponse { private SnappedPoint[] snappedPoints; private ApiError error; @@ -183,7 +183,7 @@ public ApiException getError() { } } - private static class SpeedsResponse implements ApiResponse { + public static class SpeedsResponse implements ApiResponse { private SpeedLimit[] speedLimits; private ApiError error; @@ -203,7 +203,7 @@ public ApiException getError() { } } - private static class CombinedResponse implements ApiResponse { + public static class CombinedResponse implements ApiResponse { private SnappedPoint[] snappedPoints; private SpeedLimit[] speedLimits; private ApiError error; diff --git a/src/main/java/com/google/maps/TextSearchRequest.java b/src/main/java/com/google/maps/TextSearchRequest.java index c119d4d06..0f73f6d5b 100644 --- a/src/main/java/com/google/maps/TextSearchRequest.java +++ b/src/main/java/com/google/maps/TextSearchRequest.java @@ -168,8 +168,9 @@ protected void validateRequest() { return; } - if (!params().containsKey("query")) { - throw new IllegalArgumentException("Request must contain 'query' or a 'pageToken'."); + if (!params().containsKey("query") && !params().containsKey("type")) { + throw new IllegalArgumentException( + "Request must contain 'query' or a 'pageToken'. If a 'type' is specified 'query' becomes optional."); } if (params().containsKey("location") && !params().containsKey("radius")) { diff --git a/src/main/java/com/google/maps/model/AddressComponentType.java b/src/main/java/com/google/maps/model/AddressComponentType.java index ca23e85ec..3b1dea0a7 100644 --- a/src/main/java/com/google/maps/model/AddressComponentType.java +++ b/src/main/java/com/google/maps/model/AddressComponentType.java @@ -259,6 +259,9 @@ public enum AddressComponentType { /** An RV park. */ RV_PARK("rv_park"), + /** A meal delivery establishment. */ + MEAL_DELIVERY("meal_delivery"), + /** * Indicates an unknown address component type returned by the server. The Java Client for Google * Maps Services should be updated to support the new value. diff --git a/src/main/java/com/google/maps/model/AutocompletePrediction.java b/src/main/java/com/google/maps/model/AutocompletePrediction.java index 0cd37c58c..219c3ed9b 100644 --- a/src/main/java/com/google/maps/model/AutocompletePrediction.java +++ b/src/main/java/com/google/maps/model/AutocompletePrediction.java @@ -56,7 +56,9 @@ public class AutocompletePrediction implements Serializable { * Describes the location of the entered term in the prediction result text, so that the term can * be highlighted if desired. */ - public static class MatchedSubstring { + public static class MatchedSubstring implements Serializable { + + private static final long serialVersionUID = 1L; /** The length of the matched substring, measured in Unicode characters. */ public int length; @@ -83,7 +85,9 @@ public String toString() { * Identifies each section of the returned description. (A section of the description is generally * terminated with a comma.) */ - public static class Term { + public static class Term implements Serializable { + + private static final long serialVersionUID = 1L; /** The start position of this term in the description, measured in Unicode characters. */ public int offset; diff --git a/src/main/java/com/google/maps/model/PlaceType.java b/src/main/java/com/google/maps/model/PlaceType.java index 5506c868d..a9d51f264 100644 --- a/src/main/java/com/google/maps/model/PlaceType.java +++ b/src/main/java/com/google/maps/model/PlaceType.java @@ -74,6 +74,7 @@ public enum PlaceType implements StringJoin.UrlValue { LAUNDRY("laundry"), LAWYER("lawyer"), LIBRARY("library"), + LIGHT_RAIL_STATION("light_rail_station"), LIQUOR_STORE("liquor_store"), LOCAL_GOVERNMENT_OFFICE("local_government_office"), LOCKSMITH("locksmith"), diff --git a/src/main/java/com/google/maps/model/PlacesSearchResult.java b/src/main/java/com/google/maps/model/PlacesSearchResult.java index 0e1aca23e..d5fb09369 100644 --- a/src/main/java/com/google/maps/model/PlacesSearchResult.java +++ b/src/main/java/com/google/maps/model/PlacesSearchResult.java @@ -74,6 +74,9 @@ public class PlacesSearchResult implements Serializable { /** Indicates that the place has permanently shut down. */ public boolean permanentlyClosed; + /** The number of user reviews for this place */ + public int userRatingsTotal; + @Override public String toString() { StringBuilder sb = new StringBuilder("[PlacesSearchResult: "); @@ -100,6 +103,9 @@ public String toString() { if (permanentlyClosed) { sb.append(", permanentlyClosed"); } + if (userRatingsTotal > 0) { + sb.append(", userRatingsTotal=").append(userRatingsTotal); + } sb.append("]"); return sb.toString(); diff --git a/src/test/java/com/google/maps/PlacesApiTest.java b/src/test/java/com/google/maps/PlacesApiTest.java index 319fd27f2..bd21e535c 100644 --- a/src/test/java/com/google/maps/PlacesApiTest.java +++ b/src/test/java/com/google/maps/PlacesApiTest.java @@ -471,6 +471,22 @@ public void testTextSearchRequest() throws Exception { } } + @Test + public void testTextSearchRequestWithType() throws Exception { + try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) { + LatLng location = new LatLng(-33.866611, 151.195832); + PlacesSearchResponse results = + PlacesApi.textSearchQuery(sc.context, PlaceType.ESTABLISHMENT) + .location(location) + .radius(500) + .await(); + + sc.assertParamValue(location.toUrlValue(), "location"); + sc.assertParamValue(String.valueOf(500), "radius"); + sc.assertParamValue(PlaceType.ESTABLISHMENT.toString(), "type"); + } + } + @Test(expected = IllegalArgumentException.class) public void testTextSearchLocationWithoutRadius() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) { @@ -767,6 +783,18 @@ public void testNearbySearchRequestByType() throws Exception { } } + @Test + public void testNearbySearchRequestByTypeReturnsUserRatingsTotal() throws Exception { + try (LocalTestServerContext sc = + new LocalTestServerContext(placesApiNearbySearchRequestByType)) { + PlacesSearchResponse response = + PlacesApi.nearbySearchQuery(sc.context, SYDNEY).radius(10000).type(PlaceType.BAR).await(); + + assertEquals(20, response.results.length); + assertEquals(563, response.results[0].userRatingsTotal); + } + } + @Test public void testPlaceAutocomplete() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext(placesApiPlaceAutocomplete)) { diff --git a/src/test/java/com/google/maps/model/EnumsTest.java b/src/test/java/com/google/maps/model/EnumsTest.java index 87758a3cb..e06dc9085 100644 --- a/src/test/java/com/google/maps/model/EnumsTest.java +++ b/src/test/java/com/google/maps/model/EnumsTest.java @@ -273,6 +273,7 @@ public void testCanonicalLiteralsForAddressComponentType() { m.put(AddressComponentType.MUSEUM, "museum"); m.put(AddressComponentType.RV_PARK, "rv_park"); m.put(AddressComponentType.CAMPGROUND, "campground"); + m.put(AddressComponentType.MEAL_DELIVERY, "meal_delivery"); for (Map.Entry AddressComponentTypeLiteralPair : addressComponentTypeToLiteralMap.entrySet()) {