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

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

Open jaym-inci opened this issue 5 years ago • 2 comments

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

jaym-inci avatar Nov 19 '20 06:11 jaym-inci

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

prostolyalya avatar Nov 20 '20 14:11 prostolyalya

Consider usage of ReverseGeocodeRequest in case you have geo location.

starand avatar Nov 20 '20 14:11 starand