如何从New Place SDK中的autocompletePredictions获取Place对象

时间:2019-05-23 05:09:16

标签: android google-places-api

我已经集成了Google提供的新的Place SDK。

我的自动完成方法如下。如何从响应中获取放置对象?

private fun getPlaceAutoComplete(placesClient: PlacesClient, query: String) {
        val token = AutocompleteSessionToken.newInstance()
        val request = FindAutocompletePredictionsRequest.builder()
                .setSessionToken(token)
                .setQuery(query)
                .build()
        placesClient.findAutocompletePredictions(request).addOnSuccessListener { response ->
            placeList.clear()// Place List is a List of Place Instances
            for (prediction in response.autocompletePredictions) {

                var place = prediction.getPlace()// There is no option to ge the Place.
                placeList.add(place)
            }
            setAdapter(placeList)
        }.addOnFailureListener { exception ->
            if (exception is ApiException) {
                Log.e(TAG, "Place not found: " + exception.statusCode)
            }
        }

    }

1 个答案:

答案 0 :(得分:1)

set.seed(24) clients <- data.frame(sector = sample(letters[1:10], 50, replace = TRUE), val = rnorm(50)) 类具有用于获取getPlaceId()Place ID方法。

要检索AutoCompletePrediction对象本身,必须使用对Retrieve the place details using the place ID的调用来PlacesClient.fetchPlace()。按照Migration guide

  

调用Place会启动一个Places Details SKU,其成本包括请求和属于Basic Data SKU的任何数据字段。您还可以要求Contact DataAtmosphere Data额外付费。有关更多详细信息,请参见Usage and Billing

因此,如果您担心成本,通常应该避免获取所有“地方”详细信息。