Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS opensky api call #1

Open
OscarSaharoy opened this issue Oct 14, 2022 · 0 comments
Open

JS opensky api call #1

OscarSaharoy opened this issue Oct 14, 2022 · 0 comments

Comments

@OscarSaharoy
Copy link

Hi, I love the project, Thanks for helping me out bc I'm doing something similar :)
I found how to do the opensky api call from the browser, just leaving it in case anyone is interested

export async function getFlights( coords ) {
 
     // get the user's longitude and latitude
     const [ longitude, latitude ] = [ coords.longitude, coords.latitude ];
 
     // find the min and max longitude and latitude of the search area
     const kmPerDegreeLatitude  = 111.2
     const kmPerDegreeLongitude = 111.2 * Math.cos( latitude / 180 * Math.PI )
     const latitudeDegrees  = SEARCH_DISTANCE / kmPerDegreeLatitude
     const longitudeDegrees = SEARCH_DISTANCE / kmPerDegreeLongitude
 
     // build the query string
     const parameters = {
         lamin: latitude  - latitudeDegrees,
         lomin: longitude - longitudeDegrees,
         lamax: latitude  + latitudeDegrees,
         lomax: longitude + longitudeDegrees
     }
     const queryString = new URLSearchParams(parameters).toString();
 
     // make the request and set the openskyResponse variable
     const response = await fetch( OPENSKY_URL + "?" + queryString, {method: "GET", headers: HEADERS} );
     const openskyResponse = await response.json();

    return openskyResponse;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant