rtchagas / pingplacepicker

An almost plug and play replacement for Google's Place Picker
Apache License 2.0
142 stars 55 forks source link

How to avoid producting so much Places Details request when search in the AutocompleteActivity #77

Closed DuMintong closed 4 years ago

DuMintong commented 4 years ago

Hi rtchagas,

          As we know, the google maps billing will produce when use the pingplacepicker.
  And we find that getNearbyplace()   triggers  many times fetchPlace API call when user open map ,
 that produces much billing for Places Details request.  

  Places Details SKU billing link: 
         https://developers.google.com/places/android-sdk/usage-and-billing#places-details

override fun getNearbyPlaces(location: LatLng): Single<List> {

    val locationParam = "${location.latitude},${location.longitude}"

    return googleMapsAPI.searchNearby(locationParam, PingPlacePicker.mapsApiKey)
            .flatMap { searchResult ->

                val singles = mutableListOf<Single<Place>>()

                searchResult.results.forEach {
                    singles.add(**getPlaceById(it.placeId))**
                }

private fun getPlaceById(placeId: String): Single {

    // Create the request
    val request = FetchPlaceRequest.builder(placeId, getPlaceFields()).build()

    return Single.create { emitter ->
        **googleClient.fetchPlace**(request)
                .addOnSuccessListener {
                    emitter.onSuccess(it.place)
                }
                .addOnFailureListener {
                    emitter.onError(it)
                }
    }

During the last year, we pay a considerable sum of money to google for Places Details SKU
So do you have good advice for avoiding or reduce the request times for Places Details.
Hope your feedback.
DuMintong commented 4 years ago

Because I use the old pingplcepicker version last year. And I find this issue has resolved in the latest version. So close.