扱うGeoJsonの構成が複雑で、KotlinSerialiationが通りません。

実現したいこと

-扱うGeoJsonファイルの構成を理解したい。
-KotlinSerializationを通してDataClassに変換したい

前提

GoogleMapAPIを使用して、AndroidStudioでマップを表示。
そこから日本の都道府県を区別したいので、ポリゴンで区別(他にいい方法があれば教えてください。パズルのようなイメージ)しようとしています。

そこでhttps://japonyol.net/editor/article/47-prefectures-geojson.html
のサイトからポリゴンデータを取得したのですが、そのGeoJsonファイルの構成が分かりません。具体的には、]]]が何を閉じているのかが、データが多すぎてわかりません。(きれいにインデントとかつけられないのでしょうか)

実際のファイル:https://japonyol.net/editor/article/geo/prefectures.geojson

**構成の理解は二の次で、本当の課題はKotlinSerializationを通せないということです。これを解決したいです。**エラーがいくつか出ているので、//で区切っていくつか記述します。

発生している問題・エラーメッセージ

Process: com.example.googlemapapisample, PID: 11543 java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:562) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878) //////////////////////////////////////////////////////////////////////////////////////////////// [RequestTokenManager] getToken() -> BAD_AUTHENTICATION. App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/webhistory akuy: Long live credential not available. //////////////////////////////////////////////////////////////////////////////////////////// Message is Long live credential not available. akuy: Long live credential not available.

該当のソースコード

kotlin

1@Serializable2data class Coordinates(3 val coordinates: List<List<List<List<Double>>>>,4)5 6@Serializable7data class Properties(8 val pref: Int,9 val name: String, // 他のプロパティもここに追加する10)11 12@Serializable13data class Geometry(14 val type: String,15 val coordinates: Coordinates 16)17 18@Serializable19data class Metadata(20 val generated: String,21 val notice: String 22)23 24@Serializable25data class Feature(26 val type: String,27 val properties: Properties,28 val geometry: Geometry 29)30 31@Serializable32data class FeatureCollection(33 val type: String,34 val metadata: Metadata,35 val features: List<Feature>36)37 38fun testSerialize(context: Context): String {39 val assetManager = context.assets 40 val inputStream: InputStream = assetManager.open("prefectures.geojson")41 val reader = BufferedReader(InputStreamReader(inputStream))42 val stringBuilder = StringBuilder()43 var line: String? = null44 while (reader.readLine().also { line = it } != null) {45 stringBuilder.append(line)46 }47 // ファイルから読み取ったデータを返す(例:JSON文字列をパースする)48 return stringBuilder.toString()49 50}51 52@Composable53fun Test() {54 val context = LocalContext.current 55 val strForJson = testSerialize(context = context)56 57 val dataList = Json.decodeFromString<List<FeatureCollection>>(strForJson)58}

コメントを投稿

0 コメント