Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.schafer.tracker
- import com.beust.klaxon.Klaxon
- import java.net.URL
- import kotlin.math.abs
- class airplaneTracker() {
- init {
- val apiResponse = URL("https://opensky-network.org/api/states/all").readText()
- val data = Klaxon()
- .parse<data>(
- apiResponse
- )
- val jsonData = listOf(data!!.states)
- var lowDist = 0.0
- for (x in jsonData) {
- if (x[2] == "United States") {
- val lat = x[5].toString().toDouble()
- val long = x[6].toString().toDouble()
- val R = 6371 // Radius of the earth
- val latDistance = Math.toRadians(lat - 41.661129)
- val lonDistance = Math.toRadians(long - -91.530167)
- val a =
- Math.sin(latDistance / 2) * Math.sin(latDistance / 2) + (Math.cos(Math.toRadians(41.661129)) * Math.cos(
- Math.toRadians(long)
- )
- * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2))
- val c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
- var distance = R.toDouble() * c * 1000.0 // convert to meters
- val height = abs(204 - x[7].toString().toInt()).toDouble()
- distance = Math.pow(distance, 2.0) + Math.pow(height, 2.0)
- distance = Math.sqrt(distance)
- if (distance <= lowDist || lowDist == 0.0) {
- lowDist = distance
- }
- }
- }
- println(lowDist)
- }
- companion object {
- @JvmStatic public fun main(args: Array<String>) {
- airplaneTracker()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment