Skip to content

Commit ec897e0

Browse files
committed
Draft: Location: Support moving WiFi location for Eurostar trains
1 parent ed0208a commit ec897e0

File tree

1 file changed

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

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ private val MOVING_WIFI_HOTSPOTS = setOf(
9393
"LNR On Board Wi-Fi",
9494
"LOOP on train WiFi",
9595
"WMR On Board Wi-Fi",
96+
"EurostarTrainsWiFi",
9697
// United States
9798
"Amtrak_WiFi",
9899
)
@@ -403,6 +404,34 @@ class MovingWifiHelper(private val context: Context) {
403404
}
404405
}
405406

407+
private val SOURCE_EUROSTAR = object : MovingWifiLocationSource("https://www.ombord.info/api/jsonp/position/") {
408+
override fun parse(location: Location, data: ByteArray): Location {
409+
// The API endpoint returns a JSONP object (even when no ?callback= is supplied), so strip the surrounding function call.
410+
val json = JSONObject(data.decodeToString().trim().trim('(', ')', ';'))
411+
// TODO: what happens in the Channel Tunnel? Does "satellites" go to zero? Does "mode" change?
412+
if (json.has("satellites") && json.getInt("satellites") < 1) throw RuntimeException("Eurostar has no GPS fix")
413+
location.accuracy = 100f
414+
// TODO: all values in the returned JSON are encoded as strings, including numbers. Does .getDouble() still work?
415+
location.latitude = json.getDouble("latitude")
416+
location.longitude = json.getDouble("longitude")
417+
json.optDouble("speed").takeIf { !it.isNaN() }?.let {
418+
location.speed = it.toFloat()
419+
LocationCompat.setSpeedAccuracyMetersPerSecond(location, location.speed * 0.1f)
420+
}
421+
location.time = json.getLong("time")
422+
// "cmg" means "course made good", i.e. the compass heading of the track over the ground.
423+
// Sometimes gets stuck for a few minutes, so use a generous accuracy value.
424+
json.optDouble("cmg").takeIf { !it.isNaN() }?.let {
425+
location.bearing = it.toFloat()
426+
LocationCompat.setBearingAccuracyDegrees(location, 90f)
427+
}
428+
json.optDouble("altitude").takeIf { !it.isNaN() }?.let {
429+
location.altitude = it.toFloat()
430+
}
431+
return location
432+
}
433+
}
434+
406435
private val SOURCE_AIR_CANADA = object : MovingWifiLocationSource("https://airbornemedia.inflightinternet.com/asp/api/flight/info") {
407436
override fun parse(location: Location, data: ByteArray): Location {
408437
val json = JSONObject(data.decodeToString()).getJSONObject("gpsData")
@@ -459,6 +488,7 @@ class MovingWifiHelper(private val context: Context) {
459488
"NormandieTrainConnecte" to listOf(SOURCE_NORMANDIE),
460489
"agilis-Wifi" to listOf(SOURCE_HOTSPLOTS),
461490
"Austrian FlyNet" to listOf(SOURCE_AUSTRIAN_FLYNET_EUROPE),
491+
"EurostarTrainsWiFi" to listOf(SOURCE_EUROSTAR),
462492
)
463493
}
464494
}

0 commit comments

Comments
 (0)