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

Setting fields to return with AsyncGetPlace #10945

Closed
hybp opened this issue Jun 10, 2024 · 3 comments
Closed

Setting fields to return with AsyncGetPlace #10945

hybp opened this issue Jun 10, 2024 · 3 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@hybp
Copy link

hybp commented Jun 10, 2024

Here is a sample usage getting the place details using the client.

import com.google.api.core.ApiFuture;
import com.google.maps.places.v1.GetPlaceRequest;
import com.google.maps.places.v1.Place;
import com.google.maps.places.v1.PlaceName;
import com.google.maps.places.v1.PlacesClient;

public class AsyncGetPlace {

  public static void main(String[] args) throws Exception {
    asyncGetPlace();
  }

  public static void asyncGetPlace() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (PlacesClient placesClient = PlacesClient.create()) {
      GetPlaceRequest request =
          GetPlaceRequest.newBuilder()
              .setName(PlaceName.of("[PLACE_ID]").toString())
              .setLanguageCode("languageCode-2092349083")
              .setRegionCode("regionCode-1991004415")
              .setSessionToken("sessionToken-696552189")
              .build();
      ApiFuture<Place> future = placesClient.getPlaceCallable().futureCall(request);
      // Do something.
      Place response = future.get();
    }
  }
}

I am not sure how to set the fields that I want (e.g., displayName, shortFormattedAddress, location, ...).

Same goes for SearchNearby and SearchText.

I found a github issue about this for google-cloud-python, but I couldn't find one for Java.

Thanks in advance.

@alicejli alicejli added type: question Request for information or clarification. Not an issue. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jun 20, 2024
@nicolasjandre
Copy link

I'm also facing the same issue, do you was able to figure out?

@hybp
Copy link
Author

hybp commented Jul 2, 2024

Yeah I posted this question on Stack Overflow and someone answered 2 days ago.

Here's the link: https://stackoverflow.com/questions/78594691/choosing-fields-to-return-with-places-api-new-client-library

In short, you can import

import com.google.protobuf.FieldMask

and then

GetPlaceRequest request =
          GetPlaceRequest.newBuilder()
              .setName(PlaceName.of("[PLACE_ID]").toString())
              .setLanguageCode("languageCode-2092349083")
              .setRegionCode("regionCode-1991004415")
              .setSessionToken("sessionToken-696552189")
              .setFieldMask(FieldMask.newBuilder().addPaths("formattedAddress").build())
              .build();

@hybp hybp closed this as completed Jul 2, 2024
@vedranstanic82
Copy link

This is not right for

	<dependency>
	  <groupId>com.google.maps</groupId>
	  <artifactId>google-maps-places</artifactId>
	  <version>0.17.0</version>
	</dependency>

the .setFieldMask does not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

4 participants