地点 ID 在新地点 API 中返回空值的可能性

Place Id is returning null in New Place API Likelihood

我已经实现了新的地方API,下面给出了我最近的地方列表方法。

private fun getNearestPlaceList(placesClient: PlacesClient) {
        val placeFields = Arrays.asList(Place.Field.NAME)
        val request = FindCurrentPlaceRequest.builder(placeFields).build()
        placesClient.findCurrentPlace(request).addOnSuccessListener { response ->
            placeList.clear()
            for (placeLikelihood in response.placeLikelihoods) {
                if(!placeLikelihood.place.id.isNullOrEmpty() && !placeLikelihood.place.name.isNullOrEmpty()){
                    var placeModel = PlaceModel(placeName = placeLikelihood.place.name!!, placeId = placeLikelihood.place.id!!)
                    placeList.add(placeModel)
                }
            }
            setAdapter(placeList)
        }.addOnFailureListener { exception ->
            if (exception is ApiException) {
                Log.e(TAG, "Place not found: " + exception.statusCode)
            }
        }
    }

在此 placeLikelihood.place.id 中始终返回 null。任何人都知道,我们如何从可能性中获得地点 ID?

您正在使用

val placeFields = Arrays.asList(Place.Field.NAME)

如果您想要返回 ID,您需要包含 Place.Field.ID