heremaps / here-android-sdk-examples

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

How To Get Country, State Or City Name From AutoSuggest API ? #415

Open jaym-inci opened 3 years ago

jaym-inci commented 3 years ago

Hello @heremaps

I have been trying to implement autosuggest API and I am getting successful response of autosuggest places list.

Following is my code for Autosuggets API,

val textAutoSuggestionRequest = TextAutoSuggestionRequest(query)
        textAutoSuggestionRequest.setSearchCenter(GeoCoordinate(48.263392, -123.12203))
        textAutoSuggestionRequest.execute(object : ResultListener<List<AutoSuggest>> {

            override fun onCompleted(autoSuggests: List<AutoSuggest>?, errorCode: ErrorCode?) {
                if (errorCode == ErrorCode.NONE) {
                    autoSuggests?.let {
                        m_autoSuggests!!.clear()
                        m_autoSuggests!!.addAll(it.filter {
                            it.type == AutoSuggest.Type.PLACE
                        })
                        m_autoSuggestAdapter?.notifyDataSetChanged()
                    }
                    Log.d("MapFragmentSearch0: ", "" + autoSuggests!!.size)
                } else {
                    Log.d("MapFragmentSearch1: ", "" + errorCode)
                }
            }
        })

The issue I am getting is if I'm trying to fetch data from m_autoSuggests list, I'm not able to retrieve country, state or city data from here maps response.

Log.d("autoSuggest", "${autoSuggest.title}")
            Log.d("autoSuggest", "${autoSuggest.vicinity.replace("<br/>", " ")}")
            Log.d("autoSuggest", "${autoSuggest.placeDetailsRequest}")
            Log.d("autoSuggest", "${autoSuggest.placeDetailsRequest?.locale}")
            Log.d("autoSuggest", "${autoSuggest.placeDetailsRequest?.locale?.country}")

The Output I'm getting is,

2020-11-19 12:10:12.420 1734-1734/com.droptrak.xpress D/autoSuggest: New Westminster 
2020-11-19 12:10:12.420 1734-1734/com.droptrak.xpress D/autoSuggest: Metro Vancouver, British Columbia Canada
2020-11-19 12:10:12.420 1734-1734/com.droptrak.xpress D/autoSuggest: com.here.android.mpa.search.PlaceRequest@c40e8a3
2020-11-19 12:10:12.416 1734-1734/com.droptrak.xpress D/autoSuggest: null
2020-11-19 12:10:12.420 1734-1734/com.droptrak.xpress D/autoSuggest: null

So, is there any way to retreive at least country, city or state name details?

Thanks

prostolyalya commented 3 years ago

Hello @jaym-inci. Now, there is no possibility to make a request to retrieve information about the country, city, or state.

starand commented 3 years ago

Consider usage of ReverseGeocodeRequest in case you have geo location.