- Home
- Docs
- API reference
- Snap coordinate to the nearest road network point
API reference
Snap coordinate to the nearest road network point
Finds the nearest street or highway segment to a given coordinate.
Endpoint
GET
Bearer Authhttps://api.wayline.cloud/v1/nearestRequires an API key (authentication). Product overview: Snap to Roads API. Billing: see units & pricing.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
pointrequired | query | PointString | Coordinate to snap, formatted as lat,lng. |
count | query | integer | Number of candidate snapped points to return (1 to 5).Default: 1 |
profile | query | string | Routing profile. car (default, alias driving), motorcycle (aliases bike,
motorbike, two_wheeler) or bicycle (alias cycling). A profile is served only
in regions that list it in GET /v1/coverage; otherwise the request fails with
PROFILE_UNAVAILABLE. Responses always echo the canonical name.
One of: car, driving, motorcycle, bike, motorbike, two_wheeler, bicycle, cyclingDefault: car |
Example
curl "https://api.wayline.cloud/v1/nearest?point=37.7694,-122.4862" \
-H "Authorization: Bearer $WAYLINE_API_KEY"const res = await fetch(
"https://api.wayline.cloud/v1/nearest?point=37.7694,-122.4862",
{ headers: { Authorization: `Bearer ${process.env.WAYLINE_API_KEY}` } },
);
if (!res.ok) throw new Error(`Wayline ${res.status}: ${await res.text()}`);
const data = await res.json();
console.log(data);import os, requests
res = requests.get(
"https://api.wayline.cloud/v1/nearest",
params={"point": "37.7694,-122.4862"},
headers={"Authorization": f"Bearer {os.environ['WAYLINE_API_KEY']}"},
timeout=10,
)
res.raise_for_status()
print(res.json())package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.wayline.cloud/v1/nearest?point=37.7694,-122.4862", nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("WAYLINE_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(res.Status, string(body))
}<?php
$ch = curl_init("https://api.wayline.cloud/v1/nearest?point=37.7694,-122.4862");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("WAYLINE_API_KEY")],
CURLOPT_TIMEOUT => 10,
]);
$data = json_decode(curl_exec($ch), true);
print_r($data);require "net/http"
require "json"
uri = URI("https://api.wayline.cloud/v1/nearest?point=37.7694,-122.4862")
req = Net::HTTP::Get.new(uri)
req["Authorization"] = "Bearer #{ENV.fetch("WAYLINE_API_KEY")}"
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(req) }
puts JSON.parse(res.body)import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var req = HttpRequest.newBuilder(URI.create("https://api.wayline.cloud/v1/nearest?point=37.7694,-122.4862"))
.header("Authorization", "Bearer " + System.getenv("WAYLINE_API_KEY"))
.GET().build();
var res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(res.statusCode() + " " + res.body());
}
}import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
Future<void> main() async {
final res = await http.get(
Uri.parse('https://api.wayline.cloud/v1/nearest?point=37.7694,-122.4862'),
headers: {'Authorization': 'Bearer ${Platform.environment['WAYLINE_API_KEY']}'},
);
print(jsonDecode(res.body));
}{
"request_id": "req_01JD8Q8K5Y2D",
"waypoints": [
{
"location": [
37.770599999999995,
-122.4871
],
"name": "",
"distance_meters": 38
}
],
"region": "us",
"map_version": "20261121-2330",
"units_charged": 1
}Response
200 — Successful nearest road snapping response.
| Field | Type | Description |
|---|---|---|
waypointsrequired | NearestWaypoint[] | |
waypoints[].locationrequired | Point | Flexible coordinate input accepted as string, object, or array. |
waypoints[].name | string | |
waypoints[].distance_metersrequired | integer | |
profile | string | Canonical routing profile used (car, motorcycle or bicycle). |
regionrequired | string | |
map_versionrequired | string | |
warnings | string[] | |
units_chargedrequired | integer |
Response headers
X-Request-Id— Unique identifier for tracking and debugging this request.X-RateLimit-Limit— Maximum permitted requests in current window.X-RateLimit-Remaining— Remaining request quota in current window.X-RateLimit-Reset— Seconds until the rate limit window resets.X-Units-Charged— Billable request units consumed by this request.X-Cache— Cache lookup status (`HIT` or `MISS`).X-Region— Region code serving this routing request (e.g. `bd`).
Errors
| Status | When |
|---|---|
400 | Bad request (invalid coordinates, out of coverage, too many elements, etc.). |
401 | Missing or invalid API key, or expired key. |
402 | Free quota exhausted, no payment method, account suspended, or the monthly spend limit you set was reached. Never billed. Raise or remove the limit in the dashboard (Billing) and retry; nothing else changes. |
403 | Account disabled, key IP restriction failed, origin not allowed, or scope not permitted. |
404 | No route found between the requested coordinates. |
429 | Rate limit exceeded or test key daily quota reached. |
500 | Internal server error. |
503 | Upstream routing service temporarily unavailable. |
Error bodies contain a code such as OUT_OF_COVERAGE — see the error reference.
Try it
Interactive API Console
Sends a real request from your browser using a test key (free, never billed). The key stays in this browser tab only.
No key yet? Create a free test key.