Skip to content

Commit b6f3dfe

Browse files
TimoWilkenmar-v-in
authored andcommitted
Location: Implement TGV Lyria's new position provider
The old position endpoint does not work anymore. I don't know if the other TGVs also run this new onboard system, so I have only moved the TGV Lyria provider over.
1 parent 1eca6fd commit b6f3dfe

File tree

1 file changed

+22
-1
lines changed
  • play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi

1 file changed

+22
-1
lines changed

play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,30 @@ class MovingWifiHelper(private val context: Context) {
381381
}
382382
private val SOURCE_SNCF = SncfLocationSource("https://wifi.sncf")
383383
private val SOURCE_SNCF_INTERCITES = SncfLocationSource("https://wifi.intercites.sncf")
384-
private val SOURCE_LYRIA = SncfLocationSource("https://wifi.tgv-lyria.com")
385384
private val SOURCE_NORMANDIE = SncfLocationSource("https://wifi.normandie.fr")
386385

386+
private val SOURCE_LYRIA = object : MovingWifiLocationSource("https://wifi.tgv-lyria.com/api/train/gps/position/") {
387+
/* If there is no location available (e.g. in a tunnel), the API
388+
endpoint returns HTTP 500, though it may reuse a previous
389+
location for a few seconds. The returned JSON has a
390+
"satellites" integer field, but this always seems to be 0, even
391+
when there is a valid location available.
392+
*/
393+
override fun parse(location: Location, data: ByteArray): Location {
394+
val json = JSONObject(data.decodeToString())
395+
location.accuracy = 100f
396+
location.latitude = json.getDouble("latitude")
397+
location.longitude = json.getDouble("longitude")
398+
json.optDouble("speed").takeIf { !it.isNaN() }?.let {
399+
// Speed is returned in m/s.
400+
location.speed = it.toFloat()
401+
LocationCompat.setSpeedAccuracyMetersPerSecond(location, location.speed * 0.1f)
402+
}
403+
json.optDouble("altitude").takeIf { !it.isNaN() }?.let { location.altitude = it }
404+
return location
405+
}
406+
}
407+
387408
private val SOURCE_OUIFI = object : MovingWifiLocationSource("https://ouifi.ouigo.com:8084/api/gps") {
388409
override fun parse(location: Location, data: ByteArray): Location {
389410
val json = JSONObject(data.decodeToString())

0 commit comments

Comments
 (0)