Skip to content

apiverve/airport-distance-python-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Airport Distance Calculator | APIVerve API Tutorial

License: MIT Build Python APIVerve | Airport Distance

A Python CLI tool to calculate the distance between any two airports. Enter IATA codes and get the distance in miles and kilometers, plus detailed airport information.

Screenshot


Get Your Free API Key

This tutorial requires an APIVerve API key. Sign up free - no credit card required.


Features

  • Calculate distance between any two airports
  • Distance in miles and kilometers
  • Detailed airport information
  • IATA and ICAO codes
  • City, state, country data
  • Elevation and coordinates
  • Estimated flight time
  • Popular route presets

Quick Start

  1. Clone this repository

    git clone https://github.com/apiverve/airport-distance-python-tutorial.git
    cd airport-distance-python-tutorial
  2. Install dependencies

    pip install -r requirements.txt
  3. Set your API key

    export APIVERVE_API_KEY=your-api-key-here
  4. Run the calculator

    python distance.py

Project Structure

airport-distance-python-tutorial/
├── distance.py         # Main Python script
├── requirements.txt    # Python dependencies
├── screenshot.jpg      # Preview image
├── LICENSE             # MIT license
├── .gitignore          # Git ignore rules
└── README.md           # This file

How It Works

  1. Enter two IATA airport codes
  2. API looks up both airports
  3. Calculates great-circle distance
  4. Returns full airport details

The API Call

response = requests.get('https://api.apiverve.com/v1/airportdistance',
    headers={'x-api-key': API_KEY},
    params={
        'airport1': 'JFK',
        'airport2': 'LAX'
    }
)

API Reference

Endpoint: GET https://api.apiverve.com/v1/airportdistance

Query Parameters:

Parameter Type Required Description
airport1 string Yes First airport IATA code
airport2 string Yes Second airport IATA code

Example Response:

{
  "status": "ok",
  "error": null,
  "data": {
    "distanceMiles": 2470.23,
    "distanceKm": 3974.2,
    "airport1": {
      "name": "John F Kennedy International Airport",
      "iata": "JFK",
      "icao": "KJFK",
      "city": "New York",
      "state": "New-York",
      "country": "US",
      "elevation": 13,
      "latitude": 40.63980103,
      "longitude": -73.77890015
    },
    "airport2": {
      "name": "Los Angeles International Airport",
      "iata": "LAX",
      "icao": "KLAX",
      "city": "Los Angeles",
      "state": "California",
      "country": "US",
      "elevation": 125,
      "latitude": 33.94250107,
      "longitude": -118.4079971
    }
  }
}

Airport Data Fields

Field Description
name Full airport name
iata 3-letter IATA code
icao 4-letter ICAO code
city City name
state State/province/region
country Country code
elevation Elevation in feet
latitude Latitude coordinate
longitude Longitude coordinate

Popular Routes

Route Distance
JFK → LAX 2,470 miles
LHR → JFK 3,451 miles
SFO → NRT 5,130 miles
DXB → SIN 3,637 miles
SYD → LAX 7,488 miles

Common IATA Codes

Code Airport
JFK New York JFK
LAX Los Angeles
LHR London Heathrow
CDG Paris Charles de Gaulle
NRT Tokyo Narita
DXB Dubai
SIN Singapore Changi
SYD Sydney
ORD Chicago O'Hare
ATL Atlanta

Customization Ideas

  • Add route visualization on map
  • Calculate carbon emissions
  • Compare multiple routes
  • Find nearest airports
  • Build flight search
  • Add layover calculations

Related APIs

Explore more APIs at APIVerve:

Free Plan Note

This tutorial works with the free APIVerve plan. Some APIs may have:

  • Locked fields: Premium response fields return null on free plans
  • Ignored parameters: Some optional parameters require a paid plan

The API response includes a premium object when limitations apply. Upgrade anytime to unlock all features.

License

MIT - see LICENSE

Links

About

Airport distance calculator that calculates distance between airports using Python

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages