heremaps / here-android-sdk-examples

Java-based projects using the HERE SDK for Android.
Apache License 2.0
145 stars 191 forks source link

Search for Places without a GeoCoordinates / MapView #408

Open Berki2021 opened 3 years ago

Berki2021 commented 3 years ago

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.

SergiiM commented 3 years ago

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.