{"record":{"id":"f4b79a4695313105","repo":"a-b-street/abstreet","slug":"no-road-within-of","errorCode":null,"errorMessage":"No road within {} of {}","messagePattern":"No road within (.+?) of (.+?)","errorType":"http","errorClass":null,"httpStatus":404,"severity":"warning","filePath":"headless/src/main.rs","lineNumber":415,"sourceCode":"            Ok(abstutil::to_json(\n                &map.edit_road_cmd(r, |_| {}).to_perma(map),\n            ))\n        }\n        \"/map/get-intersection-geometry\" => {\n            let i = IntersectionID(get(\"id\")?.parse::<usize>()?);\n            Ok(abstutil::to_json(&export_geometry(map, i)))\n        }\n        \"/map/get-all-geometry\" => Ok(abstutil::to_json(&map.export_geometry())),\n        \"/map/get-nearest-road\" => {\n            let pt = LonLat::new(get(\"lon\")?.parse::<f64>()?, get(\"lat\")?.parse::<f64>()?);\n            let mut closest = FindClosest::new();\n            for r in map.all_roads() {\n                closest.add(r.id, r.center_pts.points());\n            }\n            let threshold = Distance::meters(get(\"threshold_meters\")?.parse::<f64>()?);\n            match closest.closest_pt(pt.to_pt(map.get_gps_bounds()), threshold) {\n                Some((r, _)) => Ok(r.0.to_string()),\n                None => bail!(\"No road within {} of {}\", threshold, pt),\n            }\n        }\n        _ => Err(anyhow!(\"Unknown command\")),\n    }\n}\n\n// TODO I think specifying the API with protobufs or similar will be a better idea.\n\n#[derive(Serialize)]\nstruct FinishedTrip {\n    id: TripID,\n    person: PersonID,\n    duration: Option<Duration>,\n    distance_crossed: Distance,\n    mode: TripMode,\n}\n\n#[derive(Serialize)]","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/headless/src/main.rs#L397-L433","documentation":"The find-closest-road command builds a nearest-neighbor index over all roads and searches within a caller-provided threshold (in meters). If no road's center points lie within threshold of the given position, the search returns None and the server bails with this message showing the threshold and input position.","triggerScenarios":"The road-matching endpoint with threshold_meters=t and a position whose projected map point is farther than t meters from every road's center_pts.","commonSituations":"GPS coordinates outside the map bounds or projected incorrectly; coordinates belonging to a different map/city; threshold too small for GPS noise; passing lat/lon where map-space points are expected.","solutions":["Increase threshold_meters to cover GPS noise and distance to the nearest road.","Verify the position is inside the map's GPS bounds and uses the expected coordinate format (lon/lat as the endpoint expects).","Check you loaded the correct map for these coordinates.","If no road should exist there, treat the error as 'not on the road network' rather than a bug."],"exampleFix":"// before\nconst road = await post(\"/geo/find-closest-road\", { pt, threshold_meters: 5 });\n// after\nlet road;\ntry {\n  road = await post(\"/geo/find-closest-road\", { pt, threshold_meters: 5 });\n} catch (e) {\n  road = await post(\"/geo/find-closest-road\", { pt, threshold_meters: 50 });\n}","handlingStrategy":"fallback","validationCode":"// ensure the point projects inside the map bounds\nif (!map.gps_bounds.contains(pt)) throw new Error(\"point outside map\");","typeGuard":null,"tryCatchPattern":"try {\n  road = await post(\"/geo/find-closest-road\", { pt, threshold_meters: t });\n} catch (e) {\n  if (String(e).startsWith(\"No road within\")) road = null; // treat as off-network\n}","preventionTips":["Use a threshold comfortably larger than GPS error","Confirm coordinates fall within the loaded map's bounds","Verify coordinate order/format expected by the endpoint","Load the map matching the area of the coordinates"],"tags":["geo","roads","http-api","distance"],"backgroundTag":"empty-result-set","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}