import { TravelTimeClient } from 'traveltime-api'
const { TRAVELTIME_APP_ID: applicationId, TRAVELTIME_API_KEY: apiKey } = process.env
// Every place 45 minutes by public transport from King's Cross Station, counted by category
// and group: the Places layer the demo opens on
const response = await fetch('https://data.traveltimeapp.com/v1/places/cells', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Application-Id': applicationId,
'X-Api-Key': apiKey,
},
body: JSON.stringify({
cells: await reach(),
group_by: 'all',
include: 'categories,groups',
}),
})
const [{ count, category_counts, group_counts }] = (await response.json()).results
// The hexagons it counts over: everywhere 45 minutes from King's Cross, from the TravelTime API
async function reach() {
const client = new TravelTimeClient({ applicationId, apiKey })
const { results } = await client.h3Fast({
resolution: 9,
properties: ['min'],
arrival_searches: {
one_to_many: [
{ id: 'origin', coords: { lat: 51.5307, lng: -0.1238 },
transportation: { type: 'public_transport' },
arrival_time_period: 'weekday_morning', travel_time: 2700 },
],
},
})
return results[0].cells.map((cell) => cell.id)
}
The same calls from your own code: the reach with the official SDK, the data from the Data API over HTTPS. Read the docs