1

I am a beginner in kotlin and I would like to have the information contained in a url:

in my case I have a list of url, each url contains information formatted in geojson and I would like to get this information. Does anyone have an idea of how I can do this?

here is an example of the url that can be found in my list :

https://database-geojsons-test.s3.amazonaws.com/COOPERATIVES/Maps%2520test/Exploitation/Alpha/Alpha.geojson

dja
  • 53
  • 6

2 Answers2

1

It's quite simple as I use Retrofit I created a method that will retrieve the json content

@GET
    suspend fun getGeoJsonData(@Url url: String) : String

and I could retrieve the content by calling this method for each json

dja
  • 53
  • 6
1

you can use Retrofit and add a Gson converterFactory. You can read more about it on the android developer web site.

Here is just an exemple:

private val BASE_URL : String = "http [your URL]"

val interceptor: HttpLoggingInterceptor = HttpLoggingInterceptor().apply {
        this.level = HttpLoggingInterceptor.Level.BODY
    }

val client: OkHttpClient = OkHttpClient.Builder().apply {
        this.addInterceptor(interceptor)
    }.build()

private val retrofit = Retrofit.Builder()
            .baseUrl(BASE_URL)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create()) //Converters can be added to support other types in body
            .build()

I hope that works for you :)

ladytoky0
  • 588
  • 6
  • 16