@@ -5,7 +5,7 @@ import android.os.Bundle
55import android.view.View
66import androidx.appcompat.app.AppCompatActivity
77import com.google.android.material.snackbar.Snackbar
8- import com.google.gson.Gson
8+ import kotlinx.serialization.json.*
99import org.maplibre.geojson.Point
1010import org.maplibre.android.annotations.MarkerOptions
1111import org.maplibre.android.camera.CameraPosition
@@ -180,35 +180,33 @@ class ValhallaNavigationActivity :
180180 // That would allow us to skip adding fake attributes further down as well.
181181 // But this is the first step to show how the newly added banner_instructions
182182 // and voice_instructions of Valhalla can be used to generate directions directly:
183- val requestBody = mapOf (
184- " format" to " osrm" ,
185- " costing" to " auto" ,
186- " banner_instructions" to true ,
187- " voice_instructions" to true ,
188- " language" to language,
189- " directions_options" to mapOf (
190- " units" to " kilometers"
191- ),
192- " costing_options" to mapOf (
193- " auto" to mapOf (
194- " top_speed" to 130
195- )
196- ),
197- " locations" to listOf (
198- mapOf (
199- " lon" to origin.longitude(),
200- " lat" to origin.latitude(),
201- " type" to " break"
202- ),
203- mapOf (
204- " lon" to destination.longitude(),
205- " lat" to destination.latitude(),
206- " type" to " break"
207- )
208- )
209- )
210-
211- val requestBodyJson = Gson ().toJson(requestBody)
183+ val requestBodyJson = buildJsonObject {
184+ put(" format" , " osrm" )
185+ put(" costing" , " auto" )
186+ put(" banner_instructions" , true )
187+ put(" voice_instructions" , true )
188+ put(" language" , language)
189+ putJsonObject(" directions_options" ) {
190+ put(" units" , " kilometers" )
191+ }
192+ putJsonObject(" costing_options" ) {
193+ putJsonObject(" auto" ) {
194+ put(" top_speed" , 130 )
195+ }
196+ }
197+ putJsonArray(" locations" ) {
198+ addJsonObject {
199+ put(" lon" , origin.longitude())
200+ put(" lat" , origin.latitude())
201+ put(" type" , " break" )
202+ }
203+ addJsonObject {
204+ put(" lon" , destination.longitude())
205+ put(" lat" , destination.latitude())
206+ put(" type" , " break" )
207+ }
208+ }
209+ }.toString()
212210 val client = OkHttpClient ()
213211
214212 // Create request object. Requires valhalla_url to be set in developer-config.xml
0 commit comments