google-maps-services-java icon indicating copy to clipboard operation
google-maps-services-java copied to clipboard

Places: Bug: missing fields to request on place details

Open AndroidDeveloperLB opened this issue 3 years ago • 8 comments

Environment details

  1. Specify the API at the beginning of the title (for example, "Places: ...")
  2. OS type and version Android 11, but it doesn't matter
  3. Library version and other environment information implementation 'com.google.android.libraries.places:places:2.4.0'

Steps to reproduce

Try to get most updated information of a place details, after you got its basic ones via nearby-search.

Code example

  1. Suppose you use nearby-search:
        val placesClient = Places.createClient(context)
        val nearbySearchRequest = PlacesApi.nearbySearchQuery(GeoApiContext.Builder()
                .maxRetries(1)//.connectTimeout(2, TimeUnit.SECONDS).readTimeout(10, TimeUnit.SECONDS).writeTimeout(10, TimeUnit.SECONDS)
                .apiKey(apiKey).build(), latLng)
                .language(language)
        nearbySearchRequest.keyword(queryKeyword)
        nearbySearchRequest.type(placeType)
        nearbySearchRequest.rankby(RankBy.DISTANCE)
        nearbySearchRequest.setCallback(object : PendingResult.Callback<PlacesSearchResponse> {...})

From this you get an array of PlacesSearchResult: https://googlemaps.github.io/google-maps-services-java/v0.2.4/javadoc/com/google/maps/model/PlacesSearchResult.html

  1. And some time later you want to get most updated information about some place from this list, as you have its place ID. Some of them are free: https://developers.google.com/places/web-service/usage-and-billing#basic-data And some aren't: https://developers.google.com/places/web-service/usage-and-billing#contact-data

I wanted to have updated information of : name, vicinity, location (LatLng), rating, phoneNumber, websiteUri, permanentlyClosed, and openingHours.

So this is what I tried (using this: https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/net/PlacesClient#fetchPlace(com.google.android.libraries.places.api.net.FetchPlaceRequest) https://developers.google.com/places/android-sdk/place-details https://developers.google.com/places/web-service/details#PlaceDetailsResults ) :

        val placesClient = Places.createClient(context)
        val fieldsToGet = listOf(
                //basic fields: https://developers.google.com/places/web-service/usage-and-billing#basic-data
                Place.Field.NAME, Place.Field.ADDRESS, Place.Field.LAT_LNG, Place.Field.RATING,
                //extra, paid fields
                Place.Field.PHONE_NUMBER, Place.Field.WEBSITE_URI, Place.Field.OPENING_HOURS
        )
        placesClient.fetchPlace(FetchPlaceRequest.builder(googlePlace.id, fieldsToGet).build()).addOnCompleteListener { task -> ...}

The problem is, from this you get a different class called Place (here: https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/Place ) , and it has different set of fields, and some seem missing:

  • name seems to exist in both.
  • vicinity exists on PlacesSearchResult, but I can't see it on Place. However, I can see address instead.
  • location exists on PlacesSearchResult using geometry?.location and I think for Place it's on latLng, but for some reason the type for each is different...
  • rating seems to exists on both, but on Place it's Double , and on PlacesSearchResult it's Float .
  • permanentlyClosed exists only on PlacesSearchResult

How could it be? Why can't I have the same fields as on PlacesSearchResult, but updated? How can I update the permanentlyClosed ? Am I correct about the fields that do seem to match ? I've even noticed I can't set the language (useful in case the user has change the language) to query.

Am I doing things wrong?

AndroidDeveloperLB avatar Dec 30 '20 08:12 AndroidDeveloperLB

You are correct that the objects are different and the reason you're seeing this difference is because you're using two different libraries: (1) the google-maps-services-java library (i.e. this library), which is not intended for consumption on Android, and (2) the Places SDK for Android. So technically no fields are missing and this is behaving as intended.

My recommendation is to remove your dependency on this library and stick with the Places SDK for Android. If you need to get nearby places, you can use the findCurrentPlace() API or the findAutocompletePredictions() API on Android. Our sample app also demonstrates how this can be used.

arriolac avatar Feb 10 '21 17:02 arriolac

@arriolac Why isn't there an official SDK from Google for them both? This causes fragmentation and confusion. The Maps service exists for years... How can I use only the part of Google that it offers, without the other part?

What do you mean about " findCurrentPlace() API or the findAutocompletePredictions() API " ? Instead of which parts? I need to get nearby-places around some location, and then get from this result (of a list) details about each place. The "findCurrentPlace" is only about getting current location. It doesn't help at all in this. We have Fused-location API already, so why have duplicate logic ? Is it the better way? And how "findAutocompletePredictions" can help? It is meant for auto-completion, and it returns FindAutocompletePredictionsResponse, which has AutocompletePrediction in it: https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/AutocompletePrediction

Please explain what to do.

AndroidDeveloperLB avatar Feb 10 '21 18:02 AndroidDeveloperLB

I need to get nearby-places around some location, and then get from this result (of a list) details about each place.

  1. findAutocompletePredictions() will allow you to find nearby places around some location. Take a look at this sample code.
  2. For each prediction, you can get the place details using fetchPlace()

arriolac avatar Feb 10 '21 18:02 arriolac

@arriolac Why is it called this way? Why "prediction" ? Why "autoComplete" ? It's very un-intuitive when the API is about nearby-search and getting details about places.

Are you sure that this API is as complete as the current repository? And, shouldn't this repository get updated to match what's of Google (names of fields and their types) ?

AndroidDeveloperLB avatar Feb 10 '21 22:02 AndroidDeveloperLB

The suggestion I had above is the closest replacement for nearby search, although I realize that it's not a true replacement for the functionality offered by the Places API. If you need that request on your app, and the suggestions I made above won't work, then setting up a proxy is the safest way to do so.

This table contains a list of data fields not included in the Places SDK for Android which are aligned with your observations: https://developers.google.com/places/web-service/place-data-fields

arriolac avatar Feb 10 '21 23:02 arriolac

@arriolac OK so what's missing compared to what's here? I used the fields I wrote on the snippet.

On the table, it shows that "Places SDK for Android" misses Address, URL, and Vicinity. Is it what I'm supposed to look at? Or what I need already is enough there?

AndroidDeveloperLB avatar Feb 10 '21 23:02 AndroidDeveloperLB

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

stale[bot] avatar Jun 11 '21 01:06 stale[bot]

Closing this. Please reopen if you believe it should be addressed. Thank you for your contribution.

stale[bot] avatar Apr 16 '22 02:04 stale[bot]

The list of supported Place fields in Android is provided here. https://developers.google.com/maps/documentation/places/android-sdk/place-data-fields

wangela avatar Jan 30 '23 22:01 wangela

@wangela Can you please update the code to have JavaDocs to point there?

AndroidDeveloperLB avatar Jan 31 '23 08:01 AndroidDeveloperLB