【问题标题】:Place Id is returning null in New Place API Likelihood地点 ID 在新地点 API 可能性中返回 null
【发布时间】:2019-05-24 00:48:03
【问题描述】:

我已经实现了新的 Place 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)
            }
        }
    }

在这个地方Likelihood.place.id 总是返回null。任何人都知道,我们如何从可能性中获取地点 ID?

【问题讨论】:

    标签: android google-maps google-maps-api-3 google-places-api


    【解决方案1】:

    你正在使用

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

    如果要返回 ID,则需要包含 Place.Field.ID。

    【讨论】:

      猜你喜欢
      • 2015-02-24
      • 2017-05-09
      • 1970-01-01
      • 2020-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-13
      • 1970-01-01
      相关资源
      最近更新 更多