Purpose
Given {origin}, {destination}, and an optional {travel-mode}, return the visible Google Maps directions distance and estimated duration. Default to walking when the request asks for walking directions. This is read-only: do not start navigation, submit forms, or infer routes that are not rendered by Google Maps.
When to Use
- Getting walking, driving, cycling, or transit distance between named places, stations, landmarks, addresses, or intersections.
- Returning the currently displayed route duration alongside distance.
- Comparing visible alternate routes when Google Maps renders more than one option.
- Using explicit travel-mode parameters without visiting the Google homepage or typing into a Maps search box.
Workflow
- Construct the directions URL directly, encoding each origin and destination path segment independently:
https://www.google.com/maps/dir/{url-encoded-origin}/{url-encoded-destination}/?travelmode={travel-mode}&dirflg={mode-flag}For walking:
https://www.google.com/maps/dir/{url-encoded-origin}/{url-encoded-destination}/?travelmode=walking&dirflg=wUse travelmode=driving&dirflg=d for driving, travelmode=bicycling&dirflg=b for cycling, and travelmode=transit&dirflg=r for public transit. Human-readable names and addresses are valid; opaque place IDs are not required. Do not fabricate opaque IDs.
- Navigate directly once with
waitUntil: "domcontentloaded", wait about 5–8 seconds for dynamic route rendering, and run this evaluator in the same browser-agent call:
(()=>{const clean=s=>(s||'').replace(/\s+/g,' ').trim();const href=location.href,u=new URL(href),main=document.querySelector('[role="main"]')||document.body,raw=main.innerText||document.body?.innerText||'',body=clean(raw);const distanceRe=/([\d.,]+)\s*(km|m|mi|ft)\b/gi,durationRe=/(\d+(?:\s*hr)?(?:\s*\d+)?\s*(?:min|mins|minute|minutes|hr|hrs|hour|hours))\b/gi;const distances=[...body.matchAll(distanceRe)].map(m=>({value:Number(m[1].replace(/,/g,'')),unit:m[2].toLowerCase(),raw:m[0]}));const durations=[...body.matchAll(durationRe)].map(m=>m[0]);const lines=raw.split(/\n+/).map(clean).filter(Boolean);const routeLines=[...new Set(lines.filter(x=>/(?:km|\bmi\b|\bm\b|\bft\b|mins?|minutes?|hours?|hrs?)/i.test(x)))].slice(0,30);const blocked=/consent|sign in|captcha|unusual traffic|verify you are human/i.test(body)&&!/(directions|route|km|miles?|walking|driving|transit|cycling)/i.test(body);const mode=u.searchParams.get('travelmode')||(/dirflg=w/i.test(href)?'walking':/dirflg=d/i.test(href)?'driving':/dirflg=b/i.test(href)?'bicycling':/dirflg=r/i.test(href)?'transit':null);const seg=decodeURIComponent(u.pathname).match(/^\/maps\/dir\/([^/]+)\/([^/?]+)/);return{url:href,isGoogleMaps:/((^|\.)google\.com)$/.test(u.hostname)&&u.pathname.startsWith('/maps/dir/'),blocked,travelMode:mode,origin:seg?.[1]||null,destination:seg?.[2]||null,distances,durations,routeLines,bodyExcerpt:body.slice(0,2000)}})()Prefer distance and duration from the same visible route option. If multiple alternatives are rendered, return all distinct paired route records when requested; otherwise return the selected or first prominent option and preserve its raw route line as evidence. Never combine a distance from one option with a duration from another.
If the requested mode is absent, rebuild the URL with the mode-specific parameters and navigate directly again. Do not click a mode tab when the URL expresses the requested mode. If no route panel or route details render, report the blocked or unresolved state rather than estimating from coordinates.
Site-Specific Gotchas
- Google Maps directions accepts human-readable names, addresses, and station names directly in
/maps/dir/{origin}/{destination}/. - Walking mode is explicitly selected with
?travelmode=walking&dirflg=w; the mode should be included even when a no-query URL appears to resolve to the intended route. - Origins and destinations containing commas, punctuation, or spaces must be URL-encoded as individual path segments. Do not let an unencoded slash split a place into extra segments.
- Google may resolve names into a longer URL containing coordinates and opaque place IDs. Treat those as session/result evidence; never guess or persist them as reusable identifiers.
- Route details are dynamically rendered after navigation. A successful
gotomay precede the distance and duration, so wait several seconds before evaluating. - The route panel may be exposed as
[role="main"];.Fk3smhas also appeared as a route-detail container but is less durable, so the evaluator falls back to the main page and body text. - Google may render several alternatives or duplicate route-summary lines. Deduplicate evidence and keep distance/duration pairs together.
- Units and wording vary by locale (
km,m,mi,ft,min, andhr). Return exact visible raw strings in addition to parsed values where possible. - Consent, login, CAPTCHA, or unusual-traffic interstitials are blocked states. Do not infer a distance from place names or coordinates when the directions panel is absent.
- Travel estimates are time-dependent and may change with route conditions, walking access, closures, or locale. Report currently displayed estimates, not guarantees.
- Read-only: never start turn-by-turn navigation, click external booking or contact controls, or modify saved places.
Expected Output
{
"url": "https://www.google.com/maps/dir/{origin}/{destination}/?travelmode=walking&dirflg=w",
"isGoogleMaps": true,
"blocked": false,
"travelMode": "walking",
"origin": "{origin}",
"destination": "{destination}",
"distance": {"value": 0.0, "unit": "km", "raw": "0.0 km"},
"duration": "{visible duration}",
"alternatives": [],
"evidence": ["{visible route summary}"],
"bodyExcerpt": "{bounded rendered route text}"
}If blocked or unresolved, return blocked: true or null distance and duration with a concise reason. Never fabricate route distance or travel time.