@@ -115,19 +115,27 @@ private static GeoPlacesAsyncClient getGeoPlacesClient() {
115115 return geoPlacesAsyncClient ;
116116 }
117117
118+ // snippet-start:[geoplaces.java2.search.near.main]
119+ /**
120+ * Performs a nearby places search based on the provided geographic coordinates (latitude and longitude).
121+ * The method sends an asynchronous request to search for places within a 1-kilometer radius of the specified location.
122+ * The results are processed and printed once the search completes successfully.
123+ *
124+ * The search is conducted using the specified latitude and longitude for San Francisco, with the search radius
125+ * set to 1000 meters (1 kilometer).
126+ */
118127 public void searchNearBy () {
119128 double latitude = 37.7749 ; // San Francisco
120129 double longitude = -122.4194 ;
121130 List <Double > queryPosition = List .of (longitude , latitude );
122131
123- // Set up the request for searching nearby places
132+ // Set up the request for searching nearby places.
124133 SearchNearbyRequest request = SearchNearbyRequest .builder ()
125- .queryPosition (queryPosition ) // Set the position (latitude, longitude)
134+ .queryPosition (queryPosition ) // Set the position
126135 .queryRadius (1000L ) // Radius in meters (1000 meters = 1 km)
127136 .build ();
128137
129138 CompletableFuture <SearchNearbyResponse > futureResponse = getGeoPlacesClient ().searchNearby (request );
130-
131139 futureResponse .whenComplete ((response , exception ) -> {
132140 if (exception != null ) {
133141 throw new RuntimeException ("Error performing nearby search" , exception );
@@ -140,29 +148,33 @@ public void searchNearBy() {
140148 System .out .println ("Distance: " + result .distance () + " meters" );
141149 System .out .println ("-------------------------" );
142150 });
143- }).join (); // Ensures the main thread waits for completion
151+ }).join ();
144152 }
153+ // snippet-end:[geoplaces.java2.search.near.main]
145154
146-
155+ // snippet-start:[geoplaces.java2.search.text.main]
156+ /**
157+ * Searches for a place using the provided search query and prints the detailed information of the first result.
158+ *
159+ * @param searchQuery the search query to be used for the place search (ex, coffee shop)
160+ */
147161 public void searchText (String searchQuery ) {
148162 double latitude = 37.7749 ; // San Francisco
149163 double longitude = -122.4194 ;
150164 List <Double > queryPosition = List .of (longitude , latitude );
151165
152166 SearchTextRequest request = SearchTextRequest .builder ()
153- .queryText (searchQuery ) // Search for "coffee shop"
167+ .queryText (searchQuery )
154168 .biasPosition (queryPosition )
155169 .build ();
156170
157- // Asynchronous search request
158171 CompletableFuture <SearchTextResponse > futureResponse = getGeoPlacesClient ().searchText (request );
159-
160172 futureResponse .whenComplete ((response , exception ) -> {
161173 if (exception != null ) {
162174 throw new RuntimeException ("Error performing place search" , exception );
163175 }
164176
165- // Process the response and fetch detailed information about the place
177+ // Process the response and fetch detailed information about the place.
166178 response .resultItems ().stream ().findFirst ().ifPresent (result -> {
167179 String placeId = result .placeId (); // Get Place ID
168180 System .out .println ("Found Place with id: " + placeId );
@@ -178,12 +190,12 @@ public void searchText(String searchQuery) {
178190 throw new CompletionException ("Error fetching place details" , placeException );
179191 }
180192
181- // Print detailed place information
193+ // Print detailed place information.
182194 System .out .println ("Detailed Place Information:" );
183195 System .out .println ("Name: " + placeResponse .placeType ().name ());
184196 System .out .println ("Address: " + placeResponse .address ().label ());
185197
186- // Print each food type (if any)
198+ // Print each food type (if any).
187199 if (placeResponse .foodTypes () != null && !placeResponse .foodTypes ().isEmpty ()) {
188200 System .out .println ("Food Types:" );
189201 placeResponse .foodTypes ().forEach (foodType -> {
@@ -194,18 +206,24 @@ public void searchText(String searchQuery) {
194206 }
195207
196208 System .out .println ("-------------------------" );
197- }).join (); // Waits for getPlace response
209+ }).join ();
198210 });
199- }).join (); // Ensures main thread waits for completion
211+ }).join ();
200212 }
213+ // snippet-end:[geoplaces.java2.search.text.main]
201214
202-
215+ // snippet-start:[geoplaces.java2.geocode.main]
216+ /**
217+ * Performs reverse geocoding using the AWS Geo Places API.
218+ * Reverse geocoding is the process of converting geographic coordinates (latitude and longitude) to a human-readable address.
219+ * This method uses the latitude and longitude of San Francisco as the input, and prints the resulting address.
220+ */
203221 public void reverseGeocode () {
204222 double latitude = 37.7749 ; // San Francisco
205223 double longitude = -122.4194 ;
206224 System .out .println ("Use latitude 37.7749 and longitude -122.4194" );
207225
208- // AWS expects [longitude, latitude]
226+ // AWS expects [longitude, latitude].
209227 List <Double > queryPosition = List .of (longitude , latitude );
210228 ReverseGeocodeRequest request = ReverseGeocodeRequest .builder ()
211229 .queryPosition (queryPosition )
@@ -221,9 +239,9 @@ public void reverseGeocode() {
221239 response .resultItems ().forEach (result ->
222240 System .out .println ("The address is: " + result .address ().label ())
223241 );
224- }).join (); // Ensures main thread waits for completion
242+ }).join ();
225243 }
226-
244+ // snippet-end:[geoplaces.java2.geocode.main]
227245
228246 // snippet-start:[location.java2.calc.distance.main]
229247 /**
0 commit comments