Drive time
Radius versus drive time
Radius versus drive time. A circle is easy to target. A drive-time shape is what a courier or a local ad can keep. Drag the pin and compare them.
Understanding the labHow to use it and why you'd want to
Why you'd want to
The pin is rounded to two decimals, then this page asks the public Valhalla demo for 10, 20, and 30 minute drive shapes. If that fails it estimates from OSRM, and the radius rings remain either way.
How to use it
- Move the pin. It is rounded before any request.
- Valhalla is asked for the three drive-time shapes.
- If that fails, an OSRM time table estimates a ring.
- The radius rings stay on the map either way.
Map data © OpenStreetMap contributors. Dashed blue rings are 5, 10, and 15 miles. Filled shapes are 10, 20, and 30 minutes of driving when a service answers.
Same pin, two promises
The pin starts at the coarse place on this request: Columbus, OH, US. Drag it. A circle counts miles. A drive-time shape counts minutes on roads.
Asking for a drive-time shape.
Why the circle misses
A 10-mile ring includes water, a hill, and the far side of a river. A 20-minute drive follows the roads a courier or a local ad can actually reach. The gap between the two is the wasted delivery and the missed neighborhood.
How it works
- The dashed rings are straight-line miles: 5, 10, and 15.
- The filled shapes are drive time: 10, 20, and 30 minutes.
- This server asks a public Valhalla demo. No API key.
- If Valhalla does not answer, one OSRM table estimates the shape from sample points.
- If both fail, the rings remain and the page says drive time is unavailable. The pin is not stored.
Ask Valhalla for the shape
A public demo. Round the pin before you send it, and keep a fallback.
// Public Valhalla demo. No key. If it fails, keep the radius rings.
const response = await fetch("https://valhalla1.openstreetmap.de/isochrone", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
locations: [{ lat: 40.74, lon: -73.99 }],
costing: "auto",
contours: [{ time: 10 }, { time: 20 }, { time: 30 }],
polygons: true,
}),
})Or one OSRM table
Travel times from the pin to a ring of points. Connect the crossings.
// One table call: travel time from the pin to a ring of sample points.
const url = "https://router.project-osrm.org/table/v1/driving/"
+ coords
+ "?sources=0&annotations=duration"WalkthroughHow we built itShowHide
Example vendor setup is marked below. eVar and event numbers are examples. This lab does not call Adobe.
The isochrone lab rounds the pin to two decimals, asks the public Valhalla demo for 10, 20, and 30 minute drive shapes, and falls back to an OSRM time table and then to radius rings. Nothing is stored, and the lab does not call Adobe.
Round the pin before the request
driveTime rounds latitude and longitude to two decimals and refuses a pair outside the valid range. The same rounded key is cached for ten minutes.
Ask Valhalla for polygons
fromValhalla posts the pin and the three drive minutes to the public OpenStreetMap demo. It keeps Polygon and MultiPolygon rings and downsamples them.
Estimate a ring from OSRM
If Valhalla does not answer, fromOsrm asks for travel time from the pin to sample points. contourRing places one point on each ray where the time crosses 10, 20, or 30 minutes.
Keep the radius rings
When both services fail, the result is source radius and an empty contour list. The map still draws 5, 10, and 15 mile rings.
Debounce the drag
The page waits 500 milliseconds after the pin moves, then posts the coordinates to /api/lab/isochrone. The response says stored false. The lab sends no analytics event.
From the code
The pin is rounded, cached, and sent to Valhalla. A miss falls through to OSRM.
export async function driveTime(latitude: number, longitude: number): Promise<IsochroneResult> {
const lat = roundPlaces(latitude, 2)
const lng = roundPlaces(longitude, 2)
if (!coordinatesInRange(lat, lng)) {
return { source: "radius", latitude: lat, longitude: lng, contours: [], note: "unavailable", requestHost: null, stored: false }
}
const key = `${lat.toFixed(2)},${lng.toFixed(2)}`
const cached = cacheGet(key, 10 * 60 * 1000)
if (cached) return cached
const base = { latitude: lat, longitude: lng, stored: false as const }
try {
const contours = await fromValhalla(lat, lng)
if (contours) {
const result: IsochroneResult = { ...base, source: "valhalla", contours, note: "valhalla", requestHost: "valhalla1.openstreetmap.de" }
memory.set(key, { at: Date.now(), result })
return result
}
} catch {One point per ray where travel time crosses the requested seconds.
export function contourRing(rays: RayPoint[][], seconds: number): LatLng[] {
const ring: LatLng[] = []
for (const ray of rays) {
const sorted = ray.filter((point) => Number.isFinite(point.seconds) && point.seconds >= 0).sort((a, b) => a.seconds - b.seconds)
if (!sorted.length) continue
const first = sorted[0]
const last = sorted[sorted.length - 1]
if (first.seconds >= seconds) {
ring.push({ latitude: first.latitude, longitude: first.longitude })
continue
}
if (last.seconds <= seconds) {
ring.push({ latitude: last.latitude, longitude: last.longitude })
continue
}
for (let index = 1; index < sorted.length; index += 1) {
const prev = sorted[index - 1]
const next = sorted[index]Google and Adobe
This lab does not queue its own event. The Google block shows an example of how you would track the interaction. Adobe is an example too.
This lab does not queue an analytics event of its own. After Accept, the site still queues virtual_page_view for the page, with page_path and page_title. Clicks inside a data-track-ignore region are not recorded. The push below is an example, not a call this page makes. This site does not call gtag('set') or Adobe.
Example only. This page does not push this object.
// Example only. This lab does not queue this event.
dataLayer.push({
event: "drive_shape_example",
minutes: 20,
})Example implementation. This site does not call Adobe. eVar81, prop81, and event81 are example variable numbers. In Launch, a data element reads the value and a rule sends it when the value changes. In the report suite, enable eVar81 with Most Recent allocation and expire it on the hit. A processing rule is unnecessary if the data element maps straight to that eVar.
Example alloy payload. _example is a placeholder schema, not a real tenant.
alloy("sendEvent", {
xdm: {
eventType: "web.webinteraction.linkClicks",
_example: {
driveMinutes: "20",
},
},
})Example hit. eVar81 is hit-scoped in this example. prop81 dies at the same hit.
s.eVar81 = "20"
s.prop81 = "20"
s.events = "event81"
s.linkTrackVars = "eVar81,prop81,events"
s.linkTrackEvents = "event81"
s.tl(true, "o", "drive_shape_example")Translation
Each lab field, the GA4 name, and the example Adobe variable. Scope is the part that usually gets lost in the translation.
Drive minutes
GA4. Not sent. The shapes are 10, 20, and 30 minutes.
Adobe. Example eVar81, expire on the hit.
Scope. Hit. A user property would keep one drive time on later pages.
Shape source
GA4. Not sent. The page shows valhalla, osrm, or radius.
Adobe. Example prop81, which dies at the hit.
Scope. Hit. The source is a result of this request, not a visit trait.
Radius miles
GA4. Not sent. The rings are 5, 10, and 15 miles.
Adobe. Example eVar81 if you stored the ring instead of the minutes.
Scope. Event. A radius toggle is a view state.
Pin coordinates
GA4. Not sent. They are rounded to two decimals for the drive-time request and are not an analytics parameter.
Adobe. Example: do not copy the pin into eVar81.
Scope. Not a user property. The pin can be dragged on this page.
Recommended next
Why these picksReading path transitions…