Ahmed Wagdi
Ahmed Wagdi

Reputation: 4401

How to parse response of Mapbox reverse geocoding in Kotlin

I am using Mapbox in my android Kotlin application, I perform a reverse geocoding and expecting to get the full address of the place :

Here is my code:

val geoCoding = MapboxGeocoding.builder()
  .accessToken(accessToken)
  .country("eg")
  .query(Point.fromLngLat(long, lat))
  .geocodingTypes(GeocodingCriteria.TYPE_PLACE)
  .build()
println(geoCoding)

The response I got from the line println(geoCoding) is:

Geooding{query=31.23944,30.05611, mode=mapbox.places, accessToken="My access token are shown here" , baseUrl=https://api.mapbox.com, country=eg, proximity=null, geocodingTypes=place, autocomplete=null, bbox=null, limit=null, languages=null, reverseMode=null, fuzzyMatch=null, clientAppName=null

So , as you see there is no info shown at all , despite that all the info are being shown if I performed the query using a normal api URL in my chrome browser

Upvotes: 0

Views: 558

Answers (1)

Simon
Simon

Reputation: 1737

Since it's not visible from the code... Are you sure you are calling

import retrofit2.Call
import retrofit2.Callback

    geoCoding.enqueueCall(object : Callback<GeocodingResponse> {
        override fun onFailure(call: Call<GeocodingResponse>, t: Throwable) {
            Log.d("FAILURE", t.toString())
        }

        override fun onResponse(call: Call<GeocodingResponse>, response: retrofit2.Response<GeocodingResponse>) {
            Log.d("SUCCESS", response.body().toString())
        }
    })

after the .build()?

Upvotes: 2

Related Questions