I need to show list of places in dropdown
using google placeAutocomplete
widgets. Here I\'m getting dialog to show places according to my query but
kotlin:
fun queryPlaces(text: String) {
val task = object : AsyncTask(){
override fun doInBackground(vararg params: Void?): Void? {
val results = Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, text, null, null)
val autocompletePredictions = results.await()
val iterator = autocompletePredictions.iterator()
while (iterator.hasNext()) {
val prediction = iterator.next()
println("PlaceId:${prediction.placeId}")
println("PrimaryText:${prediction.getPrimaryText(null)}")
}
autocompletePredictions.release()
return null
}
}
task.execute()
}
If you want get the Place detail:
fun queryPlaces(text: String) {
val geoDataClient : GeoDataClient = Places.getGeoDataClient(context!!)
val task = object : AsyncTask(){
override fun doInBackground(vararg params: Void?): Void? {
val results = Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, text, null, null)
val autocompletePredictions = results.await()
val iterator = autocompletePredictions.iterator()
while (iterator.hasNext()) {
val prediction = iterator.next()
geoDataClient.getPlaceById(prediction.placeId).addOnCompleteListener {task->
val places = task.result
val myPlace = places?.get(0)
println("name:${myPlace?.name}")
println("latLng:${myPlace?.latLng}")
println("address:${myPlace?.address}")
}
}
autocompletePredictions.release()
return null
}
}
task.execute()
}