Reputation: 1825
I have implemented the new Place API and my nearest place list method is given below.
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)
}
}
}
In this placeLikelihood.place.id is always returning null. Anyone know, how we can get the place id from likelihood?
Upvotes: 0
Views: 435
Reputation: 199825
You're using
val placeFields = Arrays.asList(Place.Field.NAME)
You need to include Place.Field.ID
if you want an ID returned.
Upvotes: 2