Skip to content
GuidesBlogPlaygroundDashboard

Snap a coordinate to the nearest road

NearestResult routing().nearest(RoutingNearestParamsparams, RequestOptionsrequestOptions = RequestOptions.none())
GET/api/v1/nearest

Snap a coordinate to the nearest road

ParametersExpand Collapse
RoutingNearestParams params
double lat

Latitude

double lng

Longitude

Optional<String> outputFields

Comma-separated property fields to include

Optional<String> outputInclude

Extra computed fields: bbox, distance, center

Optional<Long> outputPrecision

Coordinate decimal precision (1-15, default 7)

Optional<Long> radius

Search radius in meters (default 500, max 5000)

ReturnsExpand Collapse
class NearestResult:

GeoJSON Point Feature representing the nearest point on the road network to the input coordinate. Used for snapping GPS coordinates to roads.

GeoJSON Geometry object per RFC 7946. Coordinates use [longitude, latitude] order. 3D coordinates [lng, lat, elevation] are used for elevation endpoints.

Coordinates coordinates

Coordinates array. Nesting depth varies by geometry type: Point = [lng, lat], LineString = [[lng, lat], ...], Polygon = [[[lng, lat], ...], ...], etc.

One of the following:
List<double>
List<List<double>>
List<List<List<double>>>
List<List<List<List<double>>>>
Type type

Geometry type

One of the following:
POINT("Point")
LINE_STRING("LineString")
POLYGON("Polygon")
MULTI_POINT("MultiPoint")
MULTI_LINE_STRING("MultiLineString")
MULTI_POLYGON("MultiPolygon")
Properties properties

Snap result metadata

Optional<Double> distanceM

Distance from the input coordinate to the snapped point in meters

Optional<Long> edgeId

ID of the road network edge that was snapped to

Optional<Double> edgeLengthM

Length of the matched road edge in meters

Optional<String> highway

OSM highway tag value (e.g. residential, primary, motorway)

Optional<Long> osmWayId

OSM way ID of the matched road segment

Optional<String> surface

OSM surface tag value (e.g. asphalt, gravel, paved)

Type type

Snap a coordinate to the nearest road

package com.plazafyi.example;

import com.plazafyi.client.PlazaClient;
import com.plazafyi.client.okhttp.PlazaOkHttpClient;
import com.plazafyi.models.routing.NearestResult;
import com.plazafyi.models.routing.RoutingNearestParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        PlazaClient client = PlazaOkHttpClient.fromEnv();

        RoutingNearestParams params = RoutingNearestParams.builder()
            .lat(0.0)
            .lng(0.0)
            .build();
        NearestResult nearestResult = client.routing().nearest(params);
    }
}
{
  "geometry": {
    "coordinates": [
      2.3522,
      48.8566
    ],
    "type": "Point"
  },
  "properties": {
    "distance_m": 12.4,
    "edge_id": 0,
    "edge_length_m": 0,
    "highway": "highway",
    "osm_way_id": 0,
    "surface": "surface"
  },
  "type": "Feature"
}
Returns Examples
{
  "geometry": {
    "coordinates": [
      2.3522,
      48.8566
    ],
    "type": "Point"
  },
  "properties": {
    "distance_m": 12.4,
    "edge_id": 0,
    "edge_length_m": 0,
    "highway": "highway",
    "osm_way_id": 0,
    "surface": "surface"
  },
  "type": "Feature"
}