постоение маршрута
Gitea Actions Demo / build_and_push (push) Successful in 48s
Details
Gitea Actions Demo / build_and_push (push) Successful in 48s
Details
This commit is contained in:
parent
d17cd207d8
commit
d9dfb4ae82
|
|
@ -0,0 +1,23 @@
|
||||||
|
/**
|
||||||
|
* Привязывает точку к ближайшей дороге через GraphHopper Cloud API.
|
||||||
|
* Free tier: 2000 req/день, без API key.
|
||||||
|
* Fallback: если API недоступен — возвращает исходные координаты.
|
||||||
|
*/
|
||||||
|
export async function snapToRoad(
|
||||||
|
lon: number,
|
||||||
|
lat: number,
|
||||||
|
): Promise<[number, number]> {
|
||||||
|
try {
|
||||||
|
const res = await fetch(
|
||||||
|
`https://graphhopper.com/api/1/snap?point=${lat},${lon}&layers=road`,
|
||||||
|
);
|
||||||
|
if (!res.ok) return [lon, lat];
|
||||||
|
const data: { points: { lat: number; lon: number }[] } = await res.json();
|
||||||
|
if (data.points && data.points.length > 0) {
|
||||||
|
return [data.points[0].lon, data.points[0].lat];
|
||||||
|
}
|
||||||
|
return [lon, lat];
|
||||||
|
} catch {
|
||||||
|
return [lon, lat];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue