here-android-sdk-examples icon indicating copy to clipboard operation
here-android-sdk-examples copied to clipboard

Search for Places without a GeoCoordinates / MapView

Open Berki2021 opened this issue 5 years ago • 1 comments

Is it possible to search for places, without using a mapview? I am trying to program an auto-suggestion edit text, but in the documentation, the TextQuery() needs an attribute of GeoCordinates which I simply don't have. Something like this would be nice:

@Singleton
class SearchRepositoryImpl @Inject constructor() : SearchRepository {
    private val engine = SearchEngine()
    private val searchOption = SearchOptions(null, 10)
    private val myDummyCordinates = GeoCoordinates(10.0, 10.0)

    @ExperimentalCoroutinesApi
    override fun searchPlace(query: String): LiveData<List<Suggestion>> = callbackFlow {
        val textQuery = TextQuery(query, myDummyCordinates)
        val searchCallback = SuggestCallback { _, list ->
            if (list != null) {
                sendBlocking(list as List<Suggestion>)
            }
        }
        engine.suggest(textQuery, searchOption, searchCallback)
        awaitClose {  }

    }.asLiveData()

The current approach kinda works, but the results are really really bad.

Berki2021 avatar Oct 30 '20 12:10 Berki2021

Hi @Berki2021, corresponding to docs https://developer.here.com/documentation/android-sdk-explore/4.5.1.0/api_reference/index.html?com%2Fhere%2Fsdk%2Fsearch%2FTextQuery.html second parameter stands for area center. It makes sense, because in this case you will get suggestions, that are closer to your center. So, I'd recommend to fetch somehow users current location, if you don't want to use map view. If you have a view with map before, I'd recommend to fetch its center. Hope, it helps.

SergiiM avatar Nov 11 '20 16:11 SergiiM