← All posts
tutorialtravel

How to build a trip budget calculator: cost of living, currency, and flight distance

Mahesh Naidu·5 min read

A trip budget tool needs three things: how much the destination actually costs, what the flight is going to cost in time/distance, and what the local currency is worth. The /travel namespace covers all three.

Cost of living, in three budget tiers

/cost-of-living returns destination-specific data, not a single number: a monthly budget broken into backpacker, mid-range, and comfortable tiers, plus granular line items — cheap meal, mid-range meal, local beer, 1-bedroom city-center rent — all in USD.

fetch("https://aplicious.com/api/v1/travel/cost-of-living?city=bangkok", {
  headers: { "X-API-Key": "lapi_live_••••" },
});

The three-tier structure matters because a single “average daily cost” number is close to useless — a backpacker and someone booking 4-star hotels have completely different real costs in the same city, and conflating them produces a number that's wrong for everyone.

Flight distance — real Haversine, not a lookup table

/flight-distance computes the actual great-circle distance between two coordinates using the Haversine formula, not a static city-pair lookup table:

distance_km = 2 × R × asin(√(sin²(Δlat/2) + cos(lat1) × cos(lat2) × sin²(Δlon/2)))

where R = 6371 km (Earth's radius)

Because it's a real formula rather than a lookup table, it works for any two coordinates on Earth — not just the city pairs someone thought to pre-populate.

Currency conversion

/destination-currencyresolves a country or city to its local currency and gives you a live conversion rate, so a budget built in USD can be shown in the traveller's home currency without a second API relationship.

Putting together a trip budget

async function tripBudget(city: string, days: number, tier: "backpacker" | "mid_range" | "comfortable") {
  const res = await fetch(
    `https://aplicious.com/api/v1/travel/cost-of-living?city=${city}`,
    { headers: { "X-API-Key": process.env.APLICIOUS_KEY! } }
  );
  const { data } = await res.json();
  return data.monthly_budget_usd[tier] / 30 * days;
}

Pair this with /packing-list (climate and trip-type aware) and /visa-requirements and you have most of what a pre-trip planning tool actually needs, behind one key.

Try APlicious free
One key. 34 live namespaces. 500 free calls per month — no credit card required.
Get your free API key →
← Back to all posts