Skip to content
GuidesBlogPlaygroundDashboard

Snap a coordinate to the nearest road

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

Snap a coordinate to the nearest road

ParametersExpand Collapse
params: RoutingNearestParams
lat: Double

Latitude

lng: Double

Longitude

outputFields: Optional<String>

Comma-separated property fields to include

outputInclude: Optional<String>

Extra computed fields: bbox, distance, center

outputPrecision: Optional<Long>

Coordinate decimal precision (1-15, default 7)

radius: Optional<Long>

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.

geometry: GeoJsonGeometry

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

distanceM: Optional<Double>

Distance from the input coordinate to the snapped point in meters

edgeId: Optional<Long>

ID of the road network edge that was snapped to

edgeLengthM: Optional<Double>

Length of the matched road edge in meters

highway: Optional<String>

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

osmWayId: Optional<Long>

OSM way ID of the matched road segment

surface: Optional<String>

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

fun main() {
    val client: PlazaClient = PlazaOkHttpClient.fromEnv()

    val params: RoutingNearestParams = RoutingNearestParams.builder()
        .lat(0.0)
        .lng(0.0)
        .build()
    val 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"
}