0

The most explanations on how to use the Google places api is about using Place Autocomplete or Place Picker. I have a database containing places data and would like to use the the Google places api like this:

User type location data into an Android EditText this will trigger a search both at Google places api and internally at my database.

The result of user action is a RecyclerView containing both result from Google places api and from my database.

How can I do this?

Tord Larsen
  • 2,670
  • 8
  • 33
  • 76
  • 1
    see [this](https://stackoverflow.com/a/19860624/2252830) - inside `runQuery` method call places API followed by your local sqlite query and concatenate the results into `MatrixCursor` or `MergeCursor` – pskink Nov 30 '17 at 18:53
  • 1
    and if you still want the result to be shown in `RecyclerView` then use [ths](https://gist.github.com/Shywim/127f207e7248fe48400b) adapter as a base class instead of `SimpleCursorAdapter` – pskink Nov 30 '17 at 19:50
  • Thanks this was interesting. I see now I should have mention that my database is Cloud Firestore and not as I wrote "internally at my database" , MY BAD :) – Tord Larsen Dec 01 '17 at 09:02
  • 1
    doesnt matter - `runQuery` is called in the background thread so you can get your data from any sources - from the cloud too – pskink Dec 01 '17 at 09:04
  • I think the `CursorRecyclerAdapter` you link to could be rehacked for Firestore, Instead of init it with a `Cursor` init it with a Firestore CollectionReference – Tord Larsen Dec 01 '17 at 09:07
  • Yes grate news Thanks – Tord Larsen Dec 01 '17 at 09:07
  • but what about `Google places api` results? with `Cursor` interface you can combine both sources with `MatrixCursor` – pskink Dec 01 '17 at 09:09
  • Just tried your `MatrixCursor` code (answer)you link to, in a Android Studio project. Really smart using the wikipedia like this for illustration. Do you mean I should inside the `runQuery` search both Google Places Api and my Firestore database? Yes of course I see – Tord Larsen Dec 01 '17 at 09:48
  • its the easiest solution i think, do you really need `RecyclerView` or you can use `ACTV` (like in my code i posted)? – pskink Dec 01 '17 at 09:50
  • I think i need a ListView type since the result is both Firestore and Places Api. Maybe just suppress the `ACTV` drop down and populate a recycle view with the result. User can then press each row for selection. What you think. Your MatrixCursor `ACTV` is providing a good mechanism – Tord Larsen Dec 01 '17 at 10:06
  • 1
    ok if you need multi selection so you cannot use `ACTV` and you need `CursorRecyclerAdapter` i posted in my second comment – pskink Dec 01 '17 at 10:08
  • thanks I will give it a go in my test Android Studio project – Tord Larsen Dec 01 '17 at 10:15
  • simply use `CursorRecyclerAdapter` as a base class, setup its `FilterQueryProvider` (or directly override `runQueryOnBackgroundThread` method) and call `adapter.getFilter().filter(...)` for data searching – pskink Dec 01 '17 at 10:17
  • Works grate, I just created the `FilterQueryProvider` and run the `adapter.getFilter().filter("Sweden")` and my `RecyclerView` gets populated. But I need a way for the user to type so the `AutoCompleteTextView` might come in handy again what you think? `AutoCompleteTextView` will give data for the `adapter.getFilter().filter("Sweden")` something.. – Tord Larsen Dec 01 '17 at 11:47
  • for `ACTV` to work you dont have to call `adapter.getFilter().filter("Sweden")` - it is called automagically as you type anything in `ACTV` – pskink Dec 01 '17 at 11:49
  • Yes i know what I mean is when I use the `CursorRecyclerAdapter` I need a way to insert into `adapter.getFilter().filter()` from an `EditText` or maybe from the `ACTV` – Tord Larsen Dec 01 '17 at 18:03
  • 1
    I would use SearchView - most likely in action bar, see SearchView.OnQueryTextListener - you can call `filter(...)` from `onQueryTextChange` and / or `onQueryTextSubmit` methods – pskink Dec 01 '17 at 18:09

0 Answers0