Skip to content

Instantly share code, notes, and snippets.

@mlusiak
Created April 22, 2017 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlusiak/0c934302b100a8b0f8899010fdd8422b to your computer and use it in GitHub Desktop.
Save mlusiak/0c934302b100a8b0f8899010fdd8422b to your computer and use it in GitHub Desktop.
defmodule Flightlog.FlightView do
use Flightlog.Web, :view
def download(airport) do
url = "https://airportapi02560c297e8.azurewebsites.net/api/Airports?code=gEjAp7qIbRDJRJYFYxcgZ1bl1sqCPaTBPsZLVxy5MGHRNFEU79etKw==&iataCode=" <> airport
response = HTTPotion.get url
{status, fields} = JSON.decode(response.body)
fields
end
def coords(airport) do
fields = download(airport)
{fields["lat@"], fields["lon@"]}
end
def location(airport) do
fields = download(airport)
fields["city@"] <> ", " <> fields["country@"]
end
def distance(coords1, coords2) do
Flightlog.Math.greatCircle(coords1, coords2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment